@ddd-ts/traits 0.0.36 → 0.0.37

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/package.json CHANGED
@@ -1,18 +1,27 @@
1
1
  {
2
2
  "name": "@ddd-ts/traits",
3
- "version": "0.0.36",
4
- "main": "dist/index.js",
3
+ "version": "0.0.37",
5
4
  "types": "dist/index.d.ts",
6
5
  "license": "MIT",
7
6
  "repository": {
8
7
  "url": "git+https://github.com/ddd-ts/monorepo"
9
8
  },
10
9
  "scripts": {
11
- "build": "tsc",
10
+ "build": "tsdown --config node_modules/@ddd-ts/tools/tsdown.config.js",
12
11
  "test": "jest --config node_modules/@ddd-ts/tools/jest.config.js"
13
12
  },
14
13
  "devDependencies": {
15
- "@ddd-ts/tools": "0.0.36",
14
+ "@ddd-ts/tools": "0.0.37",
16
15
  "@types/jest": "^29.5.12"
16
+ },
17
+ "exports": {
18
+ ".": "./src/index.ts",
19
+ "./package.json": "./package.json"
20
+ },
21
+ "publishConfig": {
22
+ "exports": {
23
+ ".": "./dist/index.js",
24
+ "./package.json": "./package.json"
25
+ }
17
26
  }
18
27
  }
package/dist/index.d.ts DELETED
@@ -1,99 +0,0 @@
1
- export type Constructor<in Props = any, Result extends {} = {}> = new (props: Props) => Result;
2
- export type AbstractConstructor<Props = any, Result extends {} = {}> = abstract new (props: Props) => Result;
3
- export type Trait<Factory extends <Base extends AbstractConstructor>(base: Base) => AbstractConstructor = any> = {
4
- factory: Factory;
5
- superTraits: readonly Trait<any>[];
6
- };
7
- type Explode<T> = {
8
- [P in keyof T]: T[P];
9
- };
10
- export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
11
- type MergeStaticSide<T extends readonly Trait[]> = UnionToIntersection<Explode<ReturnType<[...T][number]["factory"]>>>;
12
- export type MergeInstanceSide<T extends readonly Trait[]> = T extends [] ? {} : T extends never[] ? {} : UnionToIntersection<InstanceType<ReturnType<[...T][number]["factory"]>>>;
13
- export type MergeParameter<T extends readonly Trait[]> = T extends [] ? {} : T extends never[] ? {} : ConstructorParameters<ReturnType<[...T][number]["factory"]>>[0] extends {} ? UnionToIntersection<ConstructorParameters<ReturnType<[...T][number]["factory"]>>[0]> : ConstructorParameters<ReturnType<[...T][number]["factory"]>>[0];
14
- export type ApplyTraits<T extends readonly Trait[]> = {
15
- new (param: MergeParameter<T>): MergeInstanceSide<T>;
16
- } & MergeStaticSide<T>;
17
- export type CheckTraitRequirements<Traits extends readonly Trait[]> = CheckTraitRequirementsInternal<[], Traits>;
18
- type CheckTraitRequirementsInternal<AppliedTraits extends readonly Trait[], RemainingTraits extends readonly Trait[]> = RemainingTraits extends readonly [
19
- infer ApplyingTrait extends Trait,
20
- ...infer Rest extends Trait[]
21
- ] ? MergeParameter<AppliedTraits> extends MergeParameter<ApplyingTrait["superTraits"]> ? MergeInstanceSide<AppliedTraits> extends MergeInstanceSide<ApplyingTrait["superTraits"]> ? CheckTraitRequirementsInternal<[...AppliedTraits, ApplyingTrait], Rest> : {
22
- error: "Instance mismatch";
23
- check: "MergeInstanceSide<AppliedTraits> extends MergeInstanceSide<ApplyingTrait['superTraits']>";
24
- left: MergeInstanceSide<AppliedTraits>;
25
- right: MergeInstanceSide<ApplyingTrait["superTraits"]>;
26
- result: MergeInstanceSide<AppliedTraits> extends MergeInstanceSide<ApplyingTrait["superTraits"]> ? true : false;
27
- } : {
28
- error: "Parameter mismatch";
29
- check: "MergeParameter<AppliedTraits> extends MergeParameter<[ApplyingTrait]>";
30
- left: MergeParameter<AppliedTraits>;
31
- right: MergeParameter<[ApplyingTrait]>;
32
- result: MergeParameter<AppliedTraits> extends MergeParameter<[
33
- ApplyingTrait
34
- ]> ? true : false;
35
- } : "success";
36
- export declare function Subtrait<const SuperTraits extends readonly Trait[], Applied extends ApplyTraits<SuperTraits>, const Factory extends (base: Applied, props: ConstructorParameters<Applied>[0]) => AbstractConstructor>(superTraits: SuperTraits, factory: Factory): {
37
- factory: Factory;
38
- superTraits: SuperTraits;
39
- symbol: symbol;
40
- };
41
- export type Props<T extends {
42
- __traits_props__: any;
43
- } | Trait | Trait[]> = T extends {
44
- __traits_props__: any;
45
- } ? T["__traits_props__"] : T extends Trait ? MergeParameter<[T]> : T extends Trait[] ? MergeParameter<T> : never;
46
- export declare function Derive<R extends Trait[], C extends CheckTraitRequirements<R>>(...traits: R): C extends "success" ? ApplyTraits<R> & {
47
- __traits__: R;
48
- __traits_props__: MergeParameter<R>;
49
- } : C;
50
- export declare function WithDerivations<B extends AbstractConstructor<any>, R extends Trait[]>(base: B, ...traits: R): CheckTraitRequirementsInternal<[], [{
51
- factory: () => B;
52
- superTraits: Trait[];
53
- symbol: symbol;
54
- }, ...R]> extends infer T ? T extends CheckTraitRequirementsInternal<[], [{
55
- factory: () => B;
56
- superTraits: Trait[];
57
- symbol: symbol;
58
- }, ...R]> ? T extends "success" ? (new (param: MergeParameter<[{
59
- factory: () => B;
60
- superTraits: Trait[];
61
- symbol: symbol;
62
- }, ...R]>) => MergeInstanceSide<[{
63
- factory: () => B;
64
- superTraits: Trait[];
65
- symbol: symbol;
66
- }, ...R]>) & UnionToIntersection<Explode<ReturnType<[{
67
- factory: () => B;
68
- superTraits: Trait[];
69
- symbol: symbol;
70
- }, ...R][number]["factory"]>>> & {
71
- __traits__: [{
72
- factory: () => B;
73
- superTraits: Trait[];
74
- symbol: symbol;
75
- }, ...R];
76
- __traits_props__: MergeParameter<[{
77
- factory: () => B;
78
- superTraits: Trait[];
79
- symbol: symbol;
80
- }, ...R]>;
81
- } : T : never : never;
82
- export declare const Trait: <T extends (base: AbstractConstructor<{}, {}>) => AbstractConstructor<any, any>>(factory: T) => {
83
- factory: T;
84
- superTraits: Trait[];
85
- symbol: symbol;
86
- };
87
- export declare function implementsTrait<I extends InstanceType<any>, T extends Trait>(instance: I, trait: T): instance is ImplementsTrait<T>;
88
- export type ConstructorWithTrait<T extends Trait> = Omit<ReturnType<T["factory"]>, ""> & (new (...args: any[]) => ImplementsTrait<T>);
89
- export type HasTrait<T extends Trait | ((...args: any[]) => Trait)> = T extends (...args: any[]) => Trait ? HasTrait<ReturnType<T>> : T extends Trait ? ConstructorWithTrait<T> : never;
90
- export type ImplementsTrait<T extends Trait> = InstanceType<ReturnType<T["factory"]>>;
91
- export declare const WithProps: <P extends Record<string, any>>() => {
92
- factory: (base: AbstractConstructor<{}, {}>) => {
93
- new (props: {}): {};
94
- } & (new (props: {}) => {} & P);
95
- superTraits: Trait[];
96
- symbol: symbol;
97
- };
98
- export {};
99
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,CAAC,EAAE,CAAC,KAAK,GAAG,GAAG,EAAE,MAAM,SAAS,EAAE,GAAG,EAAE,IAAI,KAChE,KAAK,EAAE,KAAK,KACT,MAAM,CAAC;AACZ,MAAM,MAAM,mBAAmB,CAC7B,KAAK,GAAG,GAAG,EACX,MAAM,SAAS,EAAE,GAAG,EAAE,IACpB,QAAQ,MAAM,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC;AAE1C,MAAM,MAAM,KAAK,CACf,OAAO,SAAS,CAAC,IAAI,SAAS,mBAAmB,EAC/C,IAAI,EAAE,IAAI,KACP,mBAAmB,GAAG,GAAG,IAC5B;IACF,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;CACpC,CAAC;AAEF,KAAK,OAAO,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE3C,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CACnC,CAAC,SAAS,GAAG,GACT,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GACd,KAAK,CACV,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAA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AS,CACR,IAAI,EAAE,mBAAmB,CAAC,EAAE,EAAE,EAAE,CAAC,KAC9B,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,WAEzB,CAAC;;iBAG2B,KAAK,EAAE;;CAC7C,CAAC;AAEF,wBAAgB,eAAe,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,KAAK,EAC1E,QAAQ,EAAE,CAAC,EACX,KAAK,EAAE,CAAC,GACP,QAAQ,IAAI,eAAe,CAAC,CAAC,CAAC,CAEhC;AAED,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,KAAK,IAAI,IAAI,CACtD,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EACxB,EAAE,CACH,GACC,CAAC,KACC,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3B,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC,IAChE,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,GAC/B,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GACvB,CAAC,SAAS,KAAK,GACb,oBAAoB,CAAC,CAAC,CAAC,GACvB,KAAK,CAAC;AAEd,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,KAAK,IAAI,YAAY,CACzD,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CACzB,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;oDAU5B;;mCAAuB;iBAvCX,KAAK,EAAE;;CAwC1C,CAAC"}
package/dist/index.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WithProps = exports.Trait = void 0;
4
- exports.Subtrait = Subtrait;
5
- exports.Derive = Derive;
6
- exports.WithDerivations = WithDerivations;
7
- exports.implementsTrait = implementsTrait;
8
- function Subtrait(superTraits, factory) {
9
- const symbol = Symbol();
10
- return {
11
- factory,
12
- superTraits,
13
- symbol,
14
- };
15
- }
16
- function Derive(...traits) {
17
- let current = class {
18
- };
19
- for (const trait of traits) {
20
- current = trait.factory(current);
21
- }
22
- for (const trait of traits) {
23
- current[trait.symbol] = true;
24
- }
25
- return current;
26
- }
27
- function WithDerivations(base, ...traits) {
28
- return Derive((0, exports.Trait)(() => base), ...traits);
29
- }
30
- const Trait = (factory) => {
31
- const symbol = Symbol();
32
- return { factory, superTraits: [], symbol };
33
- };
34
- exports.Trait = Trait;
35
- function implementsTrait(instance, trait) {
36
- return instance.constructor[trait.symbol] === true;
37
- }
38
- const WithProps = () => (0, exports.Trait)((base) => {
39
- class Intermediate extends base {
40
- }
41
- return Intermediate;
42
- });
43
- exports.WithProps = WithProps;
44
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AA4FA,4BAcC;AAaD,wBAeC;AAED,0CAQC;AAaD,0CAKC;AAtED,SAAgB,QAAQ,CAOtB,WAAwB,EAAE,OAAgB;IAC1C,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,OAAO;QACL,OAAO;QACP,WAAW;QACX,MAAM;KACP,CAAC;AACJ,CAAC;AAaD,SAAgB,MAAM,CACpB,GAAG,MAAS;IAIZ,IAAI,OAAO,GAAgB;KAAQ,CAAC;IACpC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC1B,OAAe,CAAE,KAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACjD,CAAC;IAED,OAAO,OAAc,CAAC;AACxB,CAAC;AAED,SAAgB,eAAe,CAG7B,IAAO,EAAE,GAAG,MAAS;IACrB,OAAO,MAAM,CACX,IAAA,aAAK,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EACjB,GAAG,MAAM,CACV,CAAC;AACJ,CAAC;AAEM,MAAM,KAAK,GAAG,CAKnB,OAAU,EACV,EAAE;IACF,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,EAAa,EAAE,MAAM,EAAE,CAAC;AACzD,CAAC,CAAC;AATW,QAAA,KAAK,SAShB;AAEF,SAAgB,eAAe,CAC7B,QAAW,EACX,KAAQ;IAER,OAAQ,QAAgB,CAAC,WAAW,CAAE,KAAa,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;AACvE,CAAC;AAqBM,MAAM,SAAS,GAAG,GAAkC,EAAE,CAC3D,IAAA,aAAK,EAAC,CAAC,IAAI,EAAE,EAAE;IACb,MAAM,YAAa,SAAQ,IAAI;KAAG;IAQlC,OAAO,YAAuC,CAAC;AACjD,CAAC,CAAC,CAAC;AAXQ,QAAA,SAAS,aAWjB","sourcesContent":["export type Constructor<in Props = any, Result extends {} = {}> = new (\n props: Props,\n) => Result;\nexport type AbstractConstructor<\n Props = any,\n Result extends {} = {},\n> = abstract new (props: Props) => Result;\n\nexport type Trait<\n Factory extends <Base extends AbstractConstructor>(\n base: Base,\n ) => AbstractConstructor = any,\n> = {\n factory: Factory;\n superTraits: readonly Trait<any>[];\n};\n\ntype Explode<T> = { [P in keyof T]: T[P] };\n\nexport type UnionToIntersection<U> = (\n U extends any\n ? (k: U) => void\n : never\n) extends (k: infer I) => void\n ? I\n : never;\n\ntype MergeStaticSide<T extends readonly Trait[]> = UnionToIntersection<\n Explode<ReturnType<[...T][number][\"factory\"]>>\n>;\n\nexport type MergeInstanceSide<T extends readonly Trait[]> = T extends []\n ? {}\n : T extends never[]\n ? {}\n : UnionToIntersection<InstanceType<ReturnType<[...T][number][\"factory\"]>>>;\n\nexport type MergeParameter<T extends readonly Trait[]> = T extends []\n ? {}\n : T extends never[]\n ? {}\n : ConstructorParameters<ReturnType<[...T][number][\"factory\"]>>[0] extends {}\n ? UnionToIntersection<\n ConstructorParameters<ReturnType<[...T][number][\"factory\"]>>[0]\n >\n : ConstructorParameters<ReturnType<[...T][number][\"factory\"]>>[0];\n\nexport type ApplyTraits<T extends readonly Trait[]> = {\n new (param: MergeParameter<T>): MergeInstanceSide<T>;\n} & MergeStaticSide<T>;\n\nexport type CheckTraitRequirements<Traits extends readonly Trait[]> =\n CheckTraitRequirementsInternal<[], Traits>;\n\ntype CheckTraitRequirementsInternal<\n AppliedTraits extends readonly Trait[],\n RemainingTraits extends readonly Trait[],\n> = RemainingTraits extends readonly [\n infer ApplyingTrait extends Trait,\n ...infer Rest extends Trait[],\n]\n ? MergeParameter<AppliedTraits> extends MergeParameter<\n ApplyingTrait[\"superTraits\"]\n >\n ? MergeInstanceSide<AppliedTraits> extends MergeInstanceSide<\n ApplyingTrait[\"superTraits\"]\n >\n ? CheckTraitRequirementsInternal<[...AppliedTraits, ApplyingTrait], Rest>\n : {\n error: \"Instance mismatch\";\n check: \"MergeInstanceSide<AppliedTraits> extends MergeInstanceSide<ApplyingTrait['superTraits']>\";\n left: MergeInstanceSide<AppliedTraits>;\n right: MergeInstanceSide<ApplyingTrait[\"superTraits\"]>;\n result: MergeInstanceSide<AppliedTraits> extends MergeInstanceSide<\n ApplyingTrait[\"superTraits\"]\n >\n ? true\n : false;\n }\n : {\n error: \"Parameter mismatch\";\n check: \"MergeParameter<AppliedTraits> extends MergeParameter<[ApplyingTrait]>\";\n left: MergeParameter<AppliedTraits>;\n right: MergeParameter<[ApplyingTrait]>;\n result: MergeParameter<AppliedTraits> extends MergeParameter<\n [ApplyingTrait]\n >\n ? true\n : false;\n }\n : \"success\";\n\nexport function Subtrait<\n const SuperTraits extends readonly Trait[],\n Applied extends ApplyTraits<SuperTraits>,\n const Factory extends (\n base: Applied,\n props: ConstructorParameters<Applied>[0],\n ) => AbstractConstructor,\n>(superTraits: SuperTraits, factory: Factory) {\n const symbol = Symbol();\n return {\n factory,\n superTraits,\n symbol,\n };\n}\n\nexport type Props<T extends { __traits_props__: any } | Trait | Trait[]> =\n T extends {\n __traits_props__: any;\n }\n ? T[\"__traits_props__\"]\n : T extends Trait\n ? MergeParameter<[T]>\n : T extends Trait[]\n ? MergeParameter<T>\n : never;\n\nexport function Derive<R extends Trait[], C extends CheckTraitRequirements<R>>(\n ...traits: R\n): C extends \"success\"\n ? ApplyTraits<R> & { __traits__: R; __traits_props__: MergeParameter<R> }\n : C {\n let current: Constructor = class {};\n for (const trait of traits) {\n current = trait.factory(current);\n }\n\n for (const trait of traits) {\n (current as any)[(trait as any).symbol] = true;\n }\n\n return current as any;\n}\n\nexport function WithDerivations<\n B extends AbstractConstructor<any>,\n R extends Trait[],\n>(base: B, ...traits: R) {\n return Derive(\n Trait(() => base),\n ...traits,\n );\n}\n\nexport const Trait = <\n T extends (\n base: AbstractConstructor<{}, {}>,\n ) => AbstractConstructor<any, any>,\n>(\n factory: T,\n) => {\n const symbol = Symbol();\n return { factory, superTraits: [] as Trait[], symbol };\n};\n\nexport function implementsTrait<I extends InstanceType<any>, T extends Trait>(\n instance: I,\n trait: T,\n): instance is ImplementsTrait<T> {\n return (instance as any).constructor[(trait as any).symbol] === true;\n}\n\nexport type ConstructorWithTrait<T extends Trait> = Omit<\n ReturnType<T[\"factory\"]>,\n \"\"\n> &\n (new (\n ...args: any[]\n ) => ImplementsTrait<T>);\n\nexport type HasTrait<T extends Trait | ((...args: any[]) => Trait)> =\n T extends (...args: any[]) => Trait\n ? HasTrait<ReturnType<T>>\n : T extends Trait\n ? ConstructorWithTrait<T>\n : never;\n\nexport type ImplementsTrait<T extends Trait> = InstanceType<\n ReturnType<T[\"factory\"]>\n>;\n\nexport const WithProps = <P extends Record<string, any>>() =>\n Trait((base) => {\n class Intermediate extends base {}\n type I = typeof Intermediate extends new (\n ...args: infer A\n ) => infer T\n ? new (\n ...args: A\n ) => T & P\n : never;\n return Intermediate as typeof Intermediate & I;\n });\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":""}
@@ -1,426 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require(".");
4
- describe("Traits", () => {
5
- const Swim = (0, _1.Trait)((base) => class Swim extends base {
6
- swim() {
7
- return 1;
8
- }
9
- });
10
- const Walk = (0, _1.Trait)((base) => class extends base {
11
- walk() {
12
- return 1;
13
- }
14
- });
15
- it("derives a trait", () => {
16
- class Fish extends (0, _1.Derive)(Swim) {
17
- do() {
18
- // @ts-expect-error should be strictly typed
19
- this.test();
20
- }
21
- }
22
- const fish = new Fish({});
23
- expect(fish.swim()).toBe(1);
24
- });
25
- it("overloads a trait method", () => {
26
- class Dog extends (0, _1.Derive)(Swim) {
27
- swim() {
28
- return super.swim() * 0.2;
29
- }
30
- }
31
- const dog = new Dog({});
32
- expect(dog.swim()).toBe(0.2);
33
- });
34
- it("derives multiple traits", () => {
35
- class Dog extends (0, _1.Derive)(Swim, Walk) {
36
- }
37
- const dog = new Dog({});
38
- expect(dog.swim()).toBe(1);
39
- expect(dog.walk()).toBe(1);
40
- });
41
- const Run = (0, _1.Trait)((base) => class extends base {
42
- speed;
43
- constructor(props) {
44
- super(props);
45
- this.speed = props.speed;
46
- }
47
- run() {
48
- return 2 * this.speed;
49
- }
50
- });
51
- it("derives a trait with a constructor", () => {
52
- class Athlete extends (0, _1.Derive)(Run) {
53
- constructor() {
54
- super({ speed: 10 });
55
- }
56
- }
57
- class ErrorAthlete extends (0, _1.Derive)(Run) {
58
- constructor() {
59
- // @ts-expect-error ensures the super constructor is called with the right props
60
- super({});
61
- }
62
- }
63
- const walker = new Athlete();
64
- expect(walker.run()).toBe(20);
65
- });
66
- const Jump = (0, _1.Trait)((base) => class extends base {
67
- agility;
68
- constructor(props) {
69
- super(props);
70
- this.agility = props.agility;
71
- }
72
- jump() {
73
- return 1;
74
- }
75
- });
76
- it("derives multiple trait with a constructor", () => {
77
- class Athlete extends (0, _1.Derive)(Run, Jump) {
78
- constructor() {
79
- super({ speed: 10, agility: 10 });
80
- }
81
- }
82
- const walker = new Athlete();
83
- expect(walker.run()).toBe(20);
84
- });
85
- it("asserts an instance implements a trait", () => {
86
- const Unused = (0, _1.Trait)((base) => class extends base {
87
- constructor(props) {
88
- super(props);
89
- }
90
- });
91
- class Athlete extends (0, _1.Derive)(Run, Jump) {
92
- constructor() {
93
- super({ speed: 10, agility: 10 });
94
- }
95
- }
96
- const athlete = new Athlete();
97
- expect(athlete instanceof Athlete).toBe(true);
98
- expect((0, _1.implementsTrait)(athlete, Run)).toBe(true);
99
- expect((0, _1.implementsTrait)(athlete, Jump)).toBe(true);
100
- expect((0, _1.implementsTrait)(athlete, Unused)).toBe(false);
101
- const unknown = athlete;
102
- if ((0, _1.implementsTrait)(unknown, Run) && (0, _1.implementsTrait)(unknown, Jump)) {
103
- // if type error, ensure the type guard works
104
- unknown.run();
105
- unknown.jump();
106
- }
107
- });
108
- it("allows generic traits", () => {
109
- const Eat = () => (0, _1.Trait)((base) => class extends base {
110
- eat(_e) { }
111
- });
112
- class Animal extends (0, _1.Derive)(Eat()) {
113
- do() {
114
- this.eat("a");
115
- // @ts-expect-error should not allow to eat a number
116
- this.eat(1);
117
- }
118
- }
119
- });
120
- it("allows to easily access prop types", () => {
121
- const WithProperties = () => (0, _1.Trait)((base) => class extends base {
122
- a;
123
- b;
124
- c;
125
- constructor(props) {
126
- super(props);
127
- this.a = props.a;
128
- this.b = props.b;
129
- this.c = props.c;
130
- }
131
- });
132
- class Thing extends (0, _1.Derive)(WithProperties()) {
133
- constructor(props) {
134
- super(props);
135
- }
136
- do() {
137
- const a = this.a;
138
- const b = this.b;
139
- const c = this.c;
140
- }
141
- }
142
- });
143
- it("allows a trait to construct the base class", () => {
144
- const WithProperties = () => (0, _1.Trait)((base) => class extends base {
145
- a;
146
- b;
147
- c;
148
- constructor(props) {
149
- super(props);
150
- this.a = props.a;
151
- this.b = props.b;
152
- this.c = props.c;
153
- }
154
- static new(props) {
155
- return new this({ ...props });
156
- }
157
- });
158
- class Thing extends (0, _1.Derive)(WithProperties()) {
159
- constructor(props) {
160
- super(props);
161
- }
162
- }
163
- Thing.new({ a: "a", b: true, c: 1, d: null });
164
- });
165
- describe("Subtraits", () => {
166
- it("allows to specify supertraits", () => {
167
- const Walk = (0, _1.Trait)((base) => class Walk extends base {
168
- walk() { }
169
- });
170
- const Run = (0, _1.Subtrait)([Walk], // supertrait of subtrait defined here
171
- (base) => class Run extends base {
172
- run() {
173
- this.walk();
174
- this.walk();
175
- this.walk();
176
- }
177
- });
178
- // @ts-expect-error should not allow to create a runner without a walker
179
- class ErrorAthlete extends (0, _1.Derive)(Run) {
180
- }
181
- // @ts-expect-error ordering matters: an athlete is a Runner because it is a walker
182
- class ErrorAthlete2 extends (0, _1.Derive)(Run, Walk) {
183
- }
184
- class Athlete extends (0, _1.Derive)(Walk, Run) {
185
- do() {
186
- this.walk();
187
- this.run();
188
- }
189
- }
190
- });
191
- it("allows to specify supertraits with props", () => {
192
- const Walk = (0, _1.Trait)((base) => class extends base {
193
- walk() {
194
- return 2;
195
- }
196
- });
197
- const Run = (0, _1.Subtrait)([Walk], // supertrait of subtrait defined here
198
- (base) => class extends base {
199
- speed;
200
- constructor(props) {
201
- super({});
202
- this.speed = props.speed;
203
- }
204
- run() {
205
- return this.walk() * this.speed;
206
- }
207
- });
208
- class Athlete extends (0, _1.Derive)(Walk, Run) {
209
- constructor() {
210
- super({ speed: 10 });
211
- }
212
- start() {
213
- return this.walk() + this.run();
214
- }
215
- }
216
- const athlete = new Athlete();
217
- expect(athlete.start()).toBe(22);
218
- });
219
- it("ensures supertraits props are forwarded", () => {
220
- const Walk = (0, _1.Trait)((base) => class extends base {
221
- speed;
222
- constructor(props) {
223
- super(props);
224
- this.speed = props.speed;
225
- }
226
- walk() {
227
- return this.speed * 0.1;
228
- }
229
- });
230
- const Run = (0, _1.Subtrait)([Walk], // supertrait of subtrait defined here
231
- (base, Props) => class extends base {
232
- weigth;
233
- constructor(props) {
234
- super(props);
235
- this.weigth = props.weigth;
236
- }
237
- run() {
238
- return this.walk() * 10 + this.weigth;
239
- }
240
- });
241
- class Athlete extends (0, _1.Derive)(Walk, Run) {
242
- start() {
243
- return this.walk() + this.run();
244
- }
245
- }
246
- // @ts-expect-error missing subtrait props
247
- new Athlete({ speed: 10 });
248
- // @ts-expect-error missing supertrait props
249
- new Athlete({ weigth: 10 });
250
- const athlete = new Athlete({ speed: 10, weigth: 10 });
251
- expect(athlete.start()).toBe(21);
252
- });
253
- it("ensures supertraits props are forwarded with multiple subtraits", () => {
254
- const Walk = (0, _1.Trait)((base) => class Walk extends base {
255
- speed;
256
- constructor(props) {
257
- super({});
258
- this.speed = props.speed;
259
- }
260
- walk() {
261
- return this.speed * 0.1;
262
- }
263
- });
264
- const Fly = (0, _1.Trait)((base) => class Fly extends base {
265
- wings;
266
- constructor(props) {
267
- super({});
268
- this.wings = props.wings;
269
- }
270
- fly() {
271
- // @ts-expect-error wings is a number
272
- const s = this.wings;
273
- return this.wings;
274
- }
275
- });
276
- const Land = (0, _1.Subtrait)([Walk, Fly], // supertrait of subtrait defined here
277
- (base, Props) => class Land extends base {
278
- weigth;
279
- constructor(props) {
280
- super(props);
281
- this.weigth = props.weigth;
282
- }
283
- land() {
284
- return this.walk() + this.fly() - this.weigth;
285
- }
286
- });
287
- // @ts-expect-error Land requires Walk & Fly
288
- (class extends (0, _1.Derive)(Land) {
289
- });
290
- // @ts-expect-error Land requires Walk & Fly
291
- (class extends (0, _1.Derive)(Walk, Land) {
292
- });
293
- // @ts-expect-error Land requires Walk & Fly
294
- (class extends (0, _1.Derive)(Fly, Land) {
295
- });
296
- // @ts-expect-error Land requires Walk & Fly in correct order
297
- (class extends (0, _1.Derive)(Land, Walk, Fly) {
298
- });
299
- class Athlete extends (0, _1.Derive)(Walk, Fly, Land) {
300
- }
301
- // @ts-expect-error missing props
302
- new Athlete({ speed: 10 });
303
- // @ts-expect-error missing props
304
- new Athlete({ wings: 10 });
305
- // @ts-expect-error missing props
306
- new Athlete({ weigth: 10 });
307
- // @ts-expect-error missing props
308
- new Athlete({ speed: 10, weigth: 10 });
309
- // @ts-expect-error missing props
310
- new Athlete({ speed: 10, wings: 10 });
311
- // @ts-expect-error missing props
312
- new Athlete({ weigth: 10, wings: 10 });
313
- new Athlete({ speed: 10, weigth: 10, wings: 10 });
314
- });
315
- it("ensures a class can derive traits that dont depend on all other traits", () => {
316
- const Walk = (0, _1.Trait)((base) => class Walk extends base {
317
- speed;
318
- constructor(props) {
319
- super({});
320
- this.speed = props.speed;
321
- }
322
- walk() {
323
- return this.speed * 0.1;
324
- }
325
- });
326
- const Fly = (0, _1.Trait)((base) => class Fly extends base {
327
- wings;
328
- constructor(props) {
329
- super({});
330
- this.wings = props.wings;
331
- }
332
- fly() {
333
- // @ts-expect-error wings is a number
334
- const s = this.wings;
335
- return this.wings;
336
- }
337
- });
338
- const Land = (0, _1.Subtrait)([Walk], // supertrait of subtrait defined here
339
- (base, Props) => class Land extends base {
340
- weigth;
341
- constructor(props) {
342
- super(props);
343
- this.weigth = props.weigth;
344
- }
345
- land() {
346
- return this.walk() - this.weigth;
347
- }
348
- static isLander() {
349
- return true;
350
- }
351
- });
352
- // @ts-expect-error Land requires Walk & Fly
353
- (class extends (0, _1.Derive)(Land) {
354
- });
355
- // @ts-expect-error Land requires Walk
356
- (class extends (0, _1.Derive)(Fly, Land) {
357
- });
358
- // @ts-expect-error Land requires Walk & Fly in correct order
359
- (class extends (0, _1.Derive)(Land, Walk, Fly) {
360
- });
361
- // @ts-expect-error Land requires Walk & Fly in correct order
362
- (class extends (0, _1.Derive)(Fly, Land, Walk) {
363
- });
364
- class Athlete extends (0, _1.Derive)(Walk, Fly, Land) {
365
- }
366
- // @ts-expect-error missing props
367
- new Athlete({ speed: 10 });
368
- // @ts-expect-error missing props
369
- new Athlete({ wings: 10 });
370
- // @ts-expect-error missing props
371
- new Athlete({ weigth: 10 });
372
- // @ts-expect-error missing props
373
- new Athlete({ speed: 10, weigth: 10 });
374
- // @ts-expect-error missing props
375
- new Athlete({ speed: 10, wings: 10 });
376
- // @ts-expect-error missing props
377
- new Athlete({ weigth: 10, wings: 10 });
378
- new Athlete({ speed: 10, weigth: 10, wings: 10 });
379
- });
380
- });
381
- it("allow abstract traits", () => {
382
- const SomeTrait = (0, _1.Trait)((base) => {
383
- class I extends base {
384
- }
385
- return I;
386
- });
387
- const SomeSubTrait = (0, _1.Subtrait)([SomeTrait], (base, Props) => {
388
- class I extends base {
389
- constructor(props) {
390
- super(props);
391
- }
392
- }
393
- return I;
394
- });
395
- class Test extends (0, _1.Derive)(SomeTrait, SomeSubTrait) {
396
- do() {
397
- console.log("do");
398
- }
399
- }
400
- new Test({ test: 2 });
401
- // @ts-expect-error
402
- new Test({ anything: 2 });
403
- });
404
- it("allow to derive from a base class", () => {
405
- class Base {
406
- params;
407
- constructor(params) {
408
- this.params = params;
409
- }
410
- }
411
- const SomeTrait = (0, _1.Trait)((base) => {
412
- class I extends base {
413
- }
414
- return I;
415
- });
416
- class Test extends (0, _1.WithDerivations)(Base, SomeTrait) {
417
- do() {
418
- console.log("do");
419
- }
420
- }
421
- new Test({ a: "a" });
422
- // @ts-expect-error
423
- new Test(2);
424
- });
425
- });
426
- //# sourceMappingURL=index.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":";;AAAA,wBAQW;AAEX,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,MAAM,IAAI,GAAG,IAAA,QAAK,EAChB,CAAC,IAA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AC;IAC5B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,IAAI;YACW;YAAnB,YAAmB,MAAqB;gBAArB,WAAM,GAAN,MAAM,CAAe;YAAG,CAAC;SAC7C;QAED,MAAM,SAAS,GAAG,IAAA,QAAK,EAAC,CAAC,IAAI,EAAE,EAAE;YAC/B,MAAe,CAAE,SAAQ,IAAI;aAE5B;YACD,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;QAEH,MAAM,IAAK,SAAQ,IAAA,kBAAe,EAAC,IAAI,EAAE,SAAS,CAAC;YACjD,EAAE;gBACA,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACpB,CAAC;SACF;QAED,IAAI,IAAI,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QACrB,mBAAmB;QACnB,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {\n Constructor,\n Derive,\n Props,\n Subtrait,\n Trait,\n WithDerivations,\n implementsTrait,\n} from \".\";\n\ndescribe(\"Traits\", () => {\n const Swim = Trait(\n (base) =>\n class Swim extends base {\n swim() {\n return 1;\n }\n },\n );\n\n const Walk = Trait(\n (base) =>\n class extends base {\n walk() {\n return 1;\n }\n },\n );\n\n it(\"derives a trait\", () => {\n class Fish extends Derive(Swim) {\n do() {\n // @ts-expect-error should be strictly typed\n this.test();\n }\n }\n\n const fish = new Fish({});\n\n expect(fish.swim()).toBe(1);\n });\n\n it(\"overloads a trait method\", () => {\n class Dog extends Derive(Swim) {\n swim() {\n return super.swim() * 0.2;\n }\n }\n\n const dog = new Dog({});\n\n expect(dog.swim()).toBe(0.2);\n });\n\n it(\"derives multiple traits\", () => {\n class Dog extends Derive(Swim, Walk) {}\n\n const dog = new Dog({});\n\n expect(dog.swim()).toBe(1);\n expect(dog.walk()).toBe(1);\n });\n\n const Run = Trait(\n (base) =>\n class extends base {\n speed: number;\n constructor(props: { speed: number }) {\n super(props);\n this.speed = props.speed;\n }\n run() {\n return 2 * this.speed;\n }\n },\n );\n\n it(\"derives a trait with a constructor\", () => {\n class Athlete extends Derive(Run) {\n constructor() {\n super({ speed: 10 });\n }\n }\n\n class ErrorAthlete extends Derive(Run) {\n constructor() {\n // @ts-expect-error ensures the super constructor is called with the right props\n super({});\n }\n }\n\n const walker = new Athlete();\n\n expect(walker.run()).toBe(20);\n });\n\n const Jump = Trait(\n (base) =>\n class extends base {\n agility: number;\n constructor(props: { agility: number }) {\n super(props);\n this.agility = props.agility;\n }\n jump() {\n return 1;\n }\n },\n );\n\n it(\"derives multiple trait with a constructor\", () => {\n class Athlete extends Derive(Run, Jump) {\n constructor() {\n super({ speed: 10, agility: 10 });\n }\n }\n\n const walker = new Athlete();\n\n expect(walker.run()).toBe(20);\n });\n\n it(\"asserts an instance implements a trait\", () => {\n const Unused = Trait(\n (base) =>\n class extends base {\n constructor(props: { agility: number }) {\n super(props);\n }\n },\n );\n\n class Athlete extends Derive(Run, Jump) {\n constructor() {\n super({ speed: 10, agility: 10 });\n }\n }\n\n const athlete = new Athlete();\n\n expect(athlete instanceof Athlete).toBe(true);\n expect(implementsTrait(athlete, Run)).toBe(true);\n expect(implementsTrait(athlete, Jump)).toBe(true);\n expect(implementsTrait(athlete, Unused)).toBe(false);\n\n const unknown: unknown = athlete;\n if (implementsTrait(unknown, Run) && implementsTrait(unknown, Jump)) {\n // if type error, ensure the type guard works\n unknown.run();\n unknown.jump();\n }\n });\n\n it(\"allows generic traits\", () => {\n const Eat = <E>() =>\n Trait(\n (base) =>\n class extends base {\n eat(_e: E) {}\n },\n );\n\n class Animal extends Derive(Eat<string>()) {\n do() {\n this.eat(\"a\");\n // @ts-expect-error should not allow to eat a number\n this.eat(1);\n }\n }\n });\n\n it(\"allows to easily access prop types\", () => {\n const WithProperties = <T>() =>\n Trait(\n (base) =>\n class extends base {\n a: string;\n b: T;\n c: number;\n constructor(props: { a: string; b: T; c: number }) {\n super(props);\n this.a = props.a;\n this.b = props.b;\n this.c = props.c;\n }\n },\n );\n\n class Thing extends Derive(WithProperties<boolean>()) {\n constructor(props: Props<typeof Thing> & { d: null }) {\n super(props);\n }\n\n do() {\n const a: string = this.a;\n const b: boolean = this.b;\n const c: number = this.c;\n }\n }\n });\n\n it(\"allows a trait to construct the base class\", () => {\n const WithProperties = <T>() =>\n Trait(\n (base) =>\n class extends base {\n a: string;\n b: T;\n c: number;\n constructor(props: { a: string; b: T; c: number }) {\n super(props);\n this.a = props.a;\n this.b = props.b;\n this.c = props.c;\n }\n static new<T extends Constructor>(\n this: T,\n props: ConstructorParameters<T>[0],\n ) {\n return new this({ ...props }) as InstanceType<T>;\n }\n },\n );\n\n class Thing extends Derive(WithProperties<boolean>()) {\n constructor(props: Props<typeof Thing> & { d: null }) {\n super(props);\n }\n }\n\n Thing.new({ a: \"a\", b: true, c: 1, d: null });\n });\n\n describe(\"Subtraits\", () => {\n it(\"allows to specify supertraits\", () => {\n const Walk = Trait(\n (base) =>\n class Walk extends base {\n walk() {}\n },\n );\n\n const Run = Subtrait(\n [Walk], // supertrait of subtrait defined here\n (base) =>\n class Run extends base {\n run() {\n this.walk();\n this.walk();\n this.walk();\n }\n },\n );\n\n // @ts-expect-error should not allow to create a runner without a walker\n class ErrorAthlete extends Derive(Run) {}\n\n // @ts-expect-error ordering matters: an athlete is a Runner because it is a walker\n class ErrorAthlete2 extends Derive(Run, Walk) {}\n\n class Athlete extends Derive(Walk, Run) {\n do() {\n this.walk();\n this.run();\n }\n }\n });\n\n it(\"allows to specify supertraits with props\", () => {\n const Walk = Trait(\n (base) =>\n class extends base {\n walk() {\n return 2;\n }\n },\n );\n\n const Run = Subtrait(\n [Walk], // supertrait of subtrait defined here\n (base) =>\n class extends base {\n speed: number;\n constructor(props: { speed: number }) {\n super({});\n this.speed = props.speed;\n }\n run() {\n return this.walk() * this.speed;\n }\n },\n );\n\n class Athlete extends Derive(Walk, Run) {\n constructor() {\n super({ speed: 10 });\n }\n start() {\n return this.walk() + this.run();\n }\n }\n\n const athlete = new Athlete();\n\n expect(athlete.start()).toBe(22);\n });\n\n it(\"ensures supertraits props are forwarded\", () => {\n const Walk = Trait(\n (base) =>\n class extends base {\n speed: number;\n constructor(props: { speed: number }) {\n super(props);\n this.speed = props.speed;\n }\n walk() {\n return this.speed * 0.1;\n }\n },\n );\n\n const Run = Subtrait(\n [Walk], // supertrait of subtrait defined here\n (base, Props) =>\n class extends base {\n weigth: number;\n constructor(props: { weigth: number } & typeof Props) {\n super(props);\n this.weigth = props.weigth;\n }\n run() {\n return this.walk() * 10 + this.weigth;\n }\n },\n );\n\n class Athlete extends Derive(Walk, Run) {\n start() {\n return this.walk() + this.run();\n }\n }\n\n // @ts-expect-error missing subtrait props\n new Athlete({ speed: 10 });\n\n // @ts-expect-error missing supertrait props\n new Athlete({ weigth: 10 });\n\n const athlete = new Athlete({ speed: 10, weigth: 10 });\n\n expect(athlete.start()).toBe(21);\n });\n\n it(\"ensures supertraits props are forwarded with multiple subtraits\", () => {\n const Walk = Trait(\n (base) =>\n class Walk extends base {\n speed: number;\n constructor(props: { speed: number }) {\n super({});\n this.speed = props.speed;\n }\n walk() {\n return this.speed * 0.1;\n }\n },\n );\n\n const Fly = Trait(\n (base) =>\n class Fly extends base {\n wings: number;\n constructor(props: { wings: number }) {\n super({});\n this.wings = props.wings;\n }\n fly() {\n // @ts-expect-error wings is a number\n const s: string = this.wings;\n return this.wings;\n }\n },\n );\n\n const Land = Subtrait(\n [Walk, Fly], // supertrait of subtrait defined here\n (base, Props) =>\n class Land extends base {\n weigth: number;\n constructor(props: { weigth: number } & typeof Props) {\n super(props);\n this.weigth = props.weigth;\n }\n land() {\n return this.walk() + this.fly() - this.weigth;\n }\n },\n );\n\n // @ts-expect-error Land requires Walk & Fly\n (class extends Derive(Land) {});\n\n // @ts-expect-error Land requires Walk & Fly\n (class extends Derive(Walk, Land) {});\n\n // @ts-expect-error Land requires Walk & Fly\n (class extends Derive(Fly, Land) {});\n\n // @ts-expect-error Land requires Walk & Fly in correct order\n (class extends Derive(Land, Walk, Fly) {});\n\n class Athlete extends Derive(Walk, Fly, Land) {}\n\n // @ts-expect-error missing props\n new Athlete({ speed: 10 });\n // @ts-expect-error missing props\n new Athlete({ wings: 10 });\n // @ts-expect-error missing props\n new Athlete({ weigth: 10 });\n // @ts-expect-error missing props\n new Athlete({ speed: 10, weigth: 10 });\n // @ts-expect-error missing props\n new Athlete({ speed: 10, wings: 10 });\n // @ts-expect-error missing props\n new Athlete({ weigth: 10, wings: 10 });\n\n new Athlete({ speed: 10, weigth: 10, wings: 10 });\n });\n\n it(\"ensures a class can derive traits that dont depend on all other traits\", () => {\n const Walk = Trait(\n (base) =>\n class Walk extends base {\n speed: number;\n constructor(props: { speed: number }) {\n super({});\n this.speed = props.speed;\n }\n walk() {\n return this.speed * 0.1;\n }\n },\n );\n\n const Fly = Trait(\n (base) =>\n class Fly extends base {\n wings: number;\n constructor(props: { wings: number }) {\n super({});\n this.wings = props.wings;\n }\n fly() {\n // @ts-expect-error wings is a number\n const s: string = this.wings;\n return this.wings;\n }\n },\n );\n\n const Land = Subtrait(\n [Walk], // supertrait of subtrait defined here\n (base, Props) =>\n class Land extends base {\n weigth: number;\n constructor(props: { weigth: number } & typeof Props) {\n super(props);\n this.weigth = props.weigth;\n }\n land() {\n return this.walk() - this.weigth;\n }\n\n static isLander() {\n return true;\n }\n },\n );\n\n // @ts-expect-error Land requires Walk & Fly\n (class extends Derive(Land) {});\n\n // @ts-expect-error Land requires Walk\n (class extends Derive(Fly, Land) {});\n\n // @ts-expect-error Land requires Walk & Fly in correct order\n (class extends Derive(Land, Walk, Fly) {});\n // @ts-expect-error Land requires Walk & Fly in correct order\n (class extends Derive(Fly, Land, Walk) {});\n\n class Athlete extends Derive(Walk, Fly, Land) {}\n\n // @ts-expect-error missing props\n new Athlete({ speed: 10 });\n // @ts-expect-error missing props\n new Athlete({ wings: 10 });\n // @ts-expect-error missing props\n new Athlete({ weigth: 10 });\n // @ts-expect-error missing props\n new Athlete({ speed: 10, weigth: 10 });\n // @ts-expect-error missing props\n new Athlete({ speed: 10, wings: 10 });\n // @ts-expect-error missing props\n new Athlete({ weigth: 10, wings: 10 });\n\n new Athlete({ speed: 10, weigth: 10, wings: 10 });\n });\n });\n\n it(\"allow abstract traits\", () => {\n const SomeTrait = Trait((base) => {\n abstract class I extends base {\n abstract do(): void;\n }\n return I;\n });\n\n const SomeSubTrait = Subtrait([SomeTrait], (base, Props) => {\n abstract class I extends base {\n constructor(props: { test: 2 } & typeof Props) {\n super(props);\n }\n\n abstract do(): void;\n }\n return I;\n });\n\n class Test extends Derive(SomeTrait, SomeSubTrait) {\n do() {\n console.log(\"do\");\n }\n }\n\n new Test({ test: 2 });\n // @ts-expect-error\n new Test({ anything: 2 });\n });\n\n it(\"allow to derive from a base class\", () => {\n class Base {\n constructor(public params: { a: string }) {}\n }\n\n const SomeTrait = Trait((base) => {\n abstract class I extends base {\n abstract do(): void;\n }\n return I;\n });\n\n class Test extends WithDerivations(Base, SomeTrait) {\n do() {\n console.log(\"do\");\n }\n }\n\n new Test({ a: \"a\" });\n // @ts-expect-error\n new Test(2);\n });\n});\n"]}