expo-duooomi-app/lib/plugins/types.ts

19 lines
912 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 联合类型转换为交叉类型
* 联合类型是 A | B结果就是 A & B
* type Result = UnionToIntersection<string | number> => string & number
* type Result2 = UnionToIntersection<{ a: string } | { b: number }> => { a: string } & { b: number }
*/
export type UnionToIntersection<U> = (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 extends Primitive> = LiteralType | (BaseType & Record<never, never>);
export type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;