UNPKG

mix-cn

Version:

一个用于字符串拼接的小工具,常用于 class name 的拼接

26 lines (25 loc) 980 B
/** * 参数的数据类型 */ type ClassNameItem = null | number | string | boolean | undefined | (() => string) | (() => ClassNameItem[]) | ClassNameItem[] | Record<string, boolean | undefined>; /** * 使用 infer 判断出当前的数据类型 * * 字符串为具体的字符串值而非 string */ type TypeofClassNameItem<T> = T extends null | boolean | undefined ? '' : T extends readonly [unknown, infer U] ? TypeofClassNameItem<U> | '' : T extends readonly [unknown, infer U, infer V] ? TypeofClassNameItem<U> | TypeofClassNameItem<V> : T extends Record<string, boolean | undefined> ? keyof T | '' : T extends () => string ? string : T; /** * 递归判断当前返回的数据类型 */ type XCN<T> = T extends [infer U, ...infer V] ? `${U & string} ${XCN<V>}` : ''; /** * * 合并 class * * merge class name * */ export declare function xcn<T extends ClassNameItem[]>(...classNameList: T): XCN<{ [K in keyof T]: TypeofClassNameItem<T[K]>; }>; export {};