/** * 构造函数 * * @example * ``` * const Vector2Constructor: Constructor = Vector2; * ``` */ export type Constructor = (new (...args: any[]) => T); /** * 映射每个属性的类定义 * * @example * ``` * const classmap: ConstructorOf<{ Vector2: Vector2 }> = { Vector2: Vector2 }; * ``` */ export type ConstructorOf = { [P in keyof T]: Constructor; }; /** * 让T中以及所有键值中的所有键都是可选的 */ export type gPartial = { [P in keyof T]?: T[P] | gPartial; }; /** * 获取T类型中除值为KT类型以外的所有键 * * ``` * class A * { * a = 1; * f(){} * } * * var a: NonTypePropertyNames; //var a:"f" * var a1: NonTypePropertyNames; //var a:"a" * * ``` */ export type NonTypePropertyNames = { [K in keyof T]: T[K] extends KT ? never : K }[keyof T]; /** * 剔除T类型中值为KT类型的键 * ``` * class A * { * a = 1; * f(){} * } * * var a: NonTypePropertys; //var a: Pick * var a1: NonTypePropertys; //var a1: Pick * ``` */ export type NonTypePropertys = Pick>; /** * 选取T类型中值为KT类型的所有键 * * ``` * class A * { * a = 1; * f(){} * } * * var a: TypePropertyNames; //var a: "a" * var a1: TypePropertyNames; //var a1: "f" * ``` */ export type TypePropertyNames = { [K in keyof T]: T[K] extends KT ? K : never }[keyof T]; /** * 选取T类型中值为非函数类型的所有键 */ // eslint-disable-next-line @typescript-eslint/ban-types export type PropertyNames = NonTypePropertyNames; /** * 选取T类型中值为函数的所有键 * * ``` * class A * { * a = 1; * f(){} * } * * var a: FunctionPropertyNames; //var a: "f" * ``` */ // eslint-disable-next-line @typescript-eslint/ban-types export type FunctionPropertyNames = TypePropertyNames; /** * 选取T类型中值为KT类型的键 * * ``` * class A * { * a = 1; * f() { } * } * * var a: TypePropertys; //var a: Pick * var a1: TypePropertys; //var a1: Pick * ``` */ export type TypePropertys = Pick>; export type Lazy = T | ((...args: any[]) => T); export type LazyObject = { [P in keyof T]: Lazy; }; export const lazy = { getValue(lazyItem: Lazy, ...args: any[]): T { if (typeof lazyItem === 'function') { // eslint-disable-next-line prefer-spread return (lazyItem as Function).apply(undefined, args); } return lazyItem; } };