/** * 联合类型转换为交叉类型 * 联合类型是 A | B,结果就是 A & B * type Result = UnionToIntersection => string & number * type Result2 = UnionToIntersection<{ a: string } | { b: number }> => { a: string } & { b: number } */ export type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; export type Primitive = string | number | symbol | bigint | boolean | null | undefined; /** * 字面量联合类型 * type Status = LiteralUnion<'active' | 'inactive', string> => :'active' | 'inactive' | string * type Score = LiteralUnion<0 | 1 | 2 | 3, number> => 0 | 1 | 2 | 3 | number */ export type LiteralUnion = LiteralType | (BaseType & Record); export type ReturnType any> = T extends (...args: any) => infer R ? R : any;