-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
38 lines (29 loc) · 1.33 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class ParameterLess {
constructor() { }
}
class Parametered {
constructor(param1: string, param2: number) { }
}
class Parametered2
{
constructor(param3: string, param4: number) {}
}
type GenericConstructor = abstract new (...args: any) => any;
type ParaLessConstructor = abstract new () => any;
type IsClassConstructor<T> =
T extends GenericConstructor ? true : false;
type IsParameterLess<T extends abstract new (...args: any) => any> =
T extends ParaLessConstructor ? true : false;
type Result1 = IsClassConstructor<typeof ParameterLess>;
type Result2 = IsClassConstructor<typeof Parametered>;
type Result3 = IsClassConstructor<string>;
type Result4 = IsParameterLess<typeof ParameterLess>;
type Result5 = IsParameterLess<typeof Parametered>;
type CombinedParameters<T extends GenericConstructor[]> = {
[K in keyof T]: ConstructorParameters<T[K]>;
}
type Flattened<T extends any[][]> = T extends [infer A extends any[], ...infer B extends any[][]] ? [...A extends [] ? [undefined] : A, ...Flattened<B>] : [];
type clssArray = [typeof Parametered, typeof ParameterLess, typeof Parametered2];
type combined = CombinedParameters<clssArray>;
type flat = Flattened<CombinedParameters<[typeof Parametered, typeof ParameterLess, typeof Parametered2]>>;
type CombinedConstructor<T extends any[]> = new(...args: Flattened<combined>) => any;