diff --git a/src/index.ts b/src/index.ts index ee6a71d..db3fa44 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,35 @@ export type ClassName = string | boolean | null | undefined; +type FilterStrings = T extends readonly [ + infer F, + ...infer R, +] + ? F extends string + ? [F, ...FilterStrings] + : FilterStrings + : []; + +type JoinStrings = T extends readonly [ + infer F, + ...infer R, +] + ? F extends string + ? R extends readonly string[] + ? R["length"] extends 0 + ? F + : `${F} ${JoinStrings}` + : F + : never + : ""; + /** * Conditionally join classNames into a single string * @param {...String} args The expressions to evaluate * @returns {String} The joined classNames */ -function cx(...args: ClassName[]): string; +function cx( + ...args: T +): JoinStrings>; function cx(): string { let str = "", i = 0,