@bikky/compiler 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Libraries/GlobalTypes.d.ts +27 -25
- package/package.json +1 -1
|
@@ -1,43 +1,45 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
2
|
+
declare module BikkyTypes {
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
type UnionToIntersection<U> =
|
|
6
|
-
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
|
|
7
|
-
type AllConstraints<Super, Constraints> = UnionToIntersection<Constraints> extends never ? Super : Super & UnionToIntersection<Constraints>;
|
|
4
|
+
type Writable<T> = { -readonly [P in keyof T]: T[P] }
|
|
8
5
|
|
|
9
|
-
type
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
type
|
|
13
|
-
type AbstractClassArguments<T> = T extends abstract new (...args: infer A) => any ? A : never;
|
|
14
|
-
type ClassArguments<T> = T extends (new (...args: infer C) => any) ? C : never;
|
|
6
|
+
type GetConstraints<Extras> = Extras extends (Function & { prototype: infer Constraints })[] ? Constraints : never;
|
|
7
|
+
type UnionToIntersection<U> =
|
|
8
|
+
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
|
|
9
|
+
type AllConstraints<Super, Constraints> = UnionToIntersection<Constraints> extends never ? Super : Super & UnionToIntersection<Constraints>;
|
|
15
10
|
|
|
16
|
-
type
|
|
17
|
-
type
|
|
18
|
-
type
|
|
11
|
+
type Class<T> = (new (...args: any[]) => T);
|
|
12
|
+
type AbstractClass<T> = Function & { prototype: T };
|
|
13
|
+
type ClassObject<T> = T extends (new (...args: any[]) => infer C) ? C : never;
|
|
14
|
+
type AbstractClassObject<T> = T extends (Function & { prototype: infer C }) ? C : never;
|
|
15
|
+
type AbstractClassArguments<T> = T extends abstract new (...args: infer A) => any ? A : never;
|
|
16
|
+
type ClassArguments<T> = T extends (new (...args: infer C) => any) ? C : never;
|
|
19
17
|
|
|
18
|
+
type ConstructArguments<T> = T extends (new (...args: infer C) => any) ? C : never;
|
|
19
|
+
type Prototype<T> = (Function & { prototype: T });
|
|
20
|
+
type ObjectType<T> = T extends (new (...args: any[]) => infer C) ? C : never;
|
|
21
|
+
}
|
|
20
22
|
//Unfortunately Typescript doesn't currently support the following typing (as in the decorator's typing
|
|
21
23
|
// information will not properly alter typescript's typing information):
|
|
22
24
|
//First set of params are the ones supplied in the decorator, like: @mixin(common, extra1, extra2);
|
|
23
25
|
declare function mixin<
|
|
24
26
|
Super extends Object,
|
|
25
|
-
Extras extends Prototype<any>[]
|
|
26
|
-
>(common: Prototype<Super>, ...constraints: Extras): (
|
|
27
|
+
Extras extends BikkyTypes.Prototype<any>[]
|
|
28
|
+
>(common: BikkyTypes.Prototype<Super>, ...constraints: Extras): (
|
|
27
29
|
//Second set of params are the class the decorator is decorating, in this case the mixin.
|
|
28
30
|
<
|
|
29
31
|
MixinClass extends Function & { prototype: Object },
|
|
30
|
-
Mixin extends Prototype<MixinClass>,
|
|
31
|
-
ConstructorArgs extends ConstructArguments<Mixin>,
|
|
32
|
+
Mixin extends BikkyTypes.Prototype<MixinClass>,
|
|
33
|
+
ConstructorArgs extends BikkyTypes.ConstructArguments<Mixin>,
|
|
32
34
|
>
|
|
33
35
|
(mixin: MixinClass) => MixinClass & {
|
|
34
36
|
//We return a mix function that takes the class that the mixin
|
|
35
37
|
// is to be mixed onto. We want to ensure that the new class
|
|
36
38
|
// fulfills all the requirements listed with the decorator.
|
|
37
39
|
mix: <
|
|
38
|
-
Core extends AllConstraints<Super, GetConstraints<Extras>>
|
|
40
|
+
Core extends BikkyTypes.AllConstraints<Super, BikkyTypes.GetConstraints<Extras>>
|
|
39
41
|
>
|
|
40
|
-
(core: Prototype<Core>) =>
|
|
42
|
+
(core: BikkyTypes.Prototype<Core>) =>
|
|
41
43
|
//Lastly we return a function that requires the mixin's constructor arguments and returns
|
|
42
44
|
// an object which is a combination of the mixin and the provided core class.
|
|
43
45
|
(new (...args: ConstructorArgs) => Core & Mixin);
|
|
@@ -48,10 +50,10 @@ declare function mixin<
|
|
|
48
50
|
// decorators are updated.
|
|
49
51
|
declare function makeMixer<
|
|
50
52
|
MixinClass extends (new (...args: any[]) => object),
|
|
51
|
-
Mixin extends ClassObject<MixinClass>,
|
|
52
|
-
ConstructorArgs extends ConstructArguments<MixinClass>,
|
|
53
|
-
Super extends Object, Extras extends Prototype<any>[]>
|
|
54
|
-
(mixin: MixinClass, common: Prototype<Super>, ...constraints: Extras): (
|
|
55
|
-
<Core extends AllConstraints<Super, GetConstraints<Extras>>>(core: { new(...args: any[]): Core } ) =>
|
|
53
|
+
Mixin extends BikkyTypes.ClassObject<MixinClass>,
|
|
54
|
+
ConstructorArgs extends BikkyTypes.ConstructArguments<MixinClass>,
|
|
55
|
+
Super extends Object, Extras extends BikkyTypes.Prototype<any>[]>
|
|
56
|
+
(mixin: MixinClass, common: BikkyTypes.Prototype<Super>, ...constraints: Extras): (
|
|
57
|
+
<Core extends BikkyTypes.AllConstraints<Super, BikkyTypes.GetConstraints<Extras>>>(core: { new(...args: any[]): Core } ) =>
|
|
56
58
|
(new (...args: ConstructorArgs) => Core & Mixin));
|
|
57
59
|
|