-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathimpact-class-system-correct.d.ts
58 lines (50 loc) · 1.61 KB
/
impact-class-system-correct.d.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
export {};
declare global {
type ReplaceThisParameter<T, This2> = T extends (
this: infer This,
...args: infer Args
) => infer Return
? unknown extends This
? T
: (this: This2, ...args: Args) => Return
: T;
type ImpactClassMethodThis<
K extends keyof Proto,
Ctor,
Proto,
ParentProto,
> = K extends keyof ParentProto
? Proto & { constructor: Ctor; parent: ParentProto[K] }
: Proto & { constructor: Ctor };
type ImpactClassMember<K extends keyof Proto, Ctor, Proto, ParentProto> = ReplaceThisParameter<
Proto[K],
ImpactClassMethodThis<K, Ctor, Proto, ParentProto>
>;
type ImpactClassDefinition<Ctor, Proto, ParentProto> = {
[K in keyof Proto]?: ImpactClassMember<K, Ctor, Proto, ParentProto> | null;
};
type ImpactClassPrototype<Constructor, Instance> = Constructor extends new (
...args: infer Args
) => Instance
? { [K in keyof Instance]: Instance[K] } & {
init: (this: Instance, ...args: Args) => void;
staticInstantiate: (this: Instance, ...args: Args) => Instance | null | undefined;
}
: Instance;
interface ImpactClass<Instance> {
extend<ChildConstructor extends { prototype: unknown }>(
this: this,
classDefinition: ImpactClassDefinition<
ChildConstructor,
ChildConstructor['prototype'],
this['prototype']
>,
): ChildConstructor;
inject(
this: this,
classDefinition: ImpactClassDefinition<this, this['prototype'], this['prototype']>,
): void;
readonly classId: number;
readonly prototype: ImpactClassPrototype<this, Instance>;
}
}