This commit is contained in:
@@ -4,35 +4,74 @@ import { TraitExpression } from "./TraitExpression"
|
|||||||
import { ExtendPlain, StaticMembers } from "./util"
|
import { ExtendPlain, StaticMembers } from "./util"
|
||||||
|
|
||||||
|
|
||||||
type ExtendAbstractSuper<SuperExpression, Abstract> = (
|
// type ExtendAbstractSuper<SuperExpression, Abstract> = (
|
||||||
Simplify<
|
// Simplify<
|
||||||
|
// ExtendPlain<[
|
||||||
|
// ...MapTraitsToOwnAbstract<
|
||||||
|
// TraitExpression.Traits<SuperExpression>
|
||||||
|
// >,
|
||||||
|
// Abstract,
|
||||||
|
// ]>
|
||||||
|
// >
|
||||||
|
// )
|
||||||
|
// type MapTraitsToOwnAbstract<T extends readonly any[]> = {
|
||||||
|
// [K in keyof T]: Trait.OwnAbstract<T[K]>
|
||||||
|
// }
|
||||||
|
|
||||||
|
// type ExtendStaticAbstractSuper<SuperExpression extends TraitExpression<any, any>, StaticAbstract extends object> = (
|
||||||
|
// Simplify<
|
||||||
|
// ExtendPlain<[
|
||||||
|
// ...MapTraitsToOwnStaticAbstract<
|
||||||
|
// TraitExpression.Traits<SuperExpression>
|
||||||
|
// >,
|
||||||
|
// StaticAbstract,
|
||||||
|
// ]>
|
||||||
|
// >
|
||||||
|
// )
|
||||||
|
// type MapTraitsToOwnStaticAbstract<T extends readonly any[]> = {
|
||||||
|
// [K in keyof T]: Trait.OwnStaticAbstract<T[K]>
|
||||||
|
// }
|
||||||
|
|
||||||
|
type ImplSuper<
|
||||||
|
SuperExpression extends TraitExpression<
|
||||||
|
any,
|
||||||
|
Trait<any, any, any, any>[]
|
||||||
|
>,
|
||||||
|
Abstract extends object,
|
||||||
|
StaticAbstract extends object,
|
||||||
|
> = (
|
||||||
|
AbstractClass<
|
||||||
ExtendPlain<[
|
ExtendPlain<[
|
||||||
...MapTraitsToOwnAbstract<
|
...MapTraitsToOwnImplInstance<
|
||||||
TraitExpression.Traits<SuperExpression>
|
TraitExpression.Traits<SuperExpression>
|
||||||
>,
|
>,
|
||||||
Abstract,
|
Abstract,
|
||||||
]>
|
]>
|
||||||
>
|
> &
|
||||||
)
|
// ExtendPlain<[
|
||||||
|
// ...MapTraitsToOwnImplStaticMembers<
|
||||||
type MapTraitsToOwnAbstract<T extends readonly any[]> = {
|
// TraitExpression.Traits<SuperExpression>
|
||||||
[K in keyof T]: Trait.OwnAbstract<T[K]>
|
// >,
|
||||||
}
|
// StaticAbstract,
|
||||||
|
// ]>
|
||||||
|
ExtendPlain<
|
||||||
type ExtendStaticAbstractSuper<SuperExpression, StaticAbstract> = (
|
MapStaticMembers<
|
||||||
Simplify<
|
MapTraitsToOwnImplStaticMembers<
|
||||||
ExtendPlain<[
|
|
||||||
...MapTraitsToOwnStaticAbstract<
|
|
||||||
TraitExpression.Traits<SuperExpression>
|
TraitExpression.Traits<SuperExpression>
|
||||||
>,
|
>
|
||||||
StaticAbstract,
|
>
|
||||||
]>
|
|
||||||
>
|
>
|
||||||
)
|
)
|
||||||
|
type MapTraitsToOwnImplInstance<T extends readonly any[]> = {
|
||||||
type MapTraitsToOwnStaticAbstract<T extends readonly any[]> = {
|
[K in keyof T]: InstanceType<Trait.OwnImplClass<T[K]>>
|
||||||
[K in keyof T]: Trait.OwnStaticAbstract<T[K]>
|
}
|
||||||
|
type MapTraitsToOwnImplStaticMembers<T extends readonly any[]> = {
|
||||||
|
[K in keyof T]: Trait.OwnImplClass<T[K]>
|
||||||
|
}
|
||||||
|
type MapStaticMembers<Tuple extends readonly AbstractClass<any>[]> = {
|
||||||
|
[TupleK in keyof Tuple]: {
|
||||||
|
[ClassK in keyof Tuple[TupleK]]: Tuple[TupleK][ClassK]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -117,11 +156,12 @@ export class TraitBuilder<
|
|||||||
this.traitSuperExpression,
|
this.traitSuperExpression,
|
||||||
this.traitAbstract,
|
this.traitAbstract,
|
||||||
this.traitStaticAbstract,
|
this.traitStaticAbstract,
|
||||||
apply as unknown as (Super: AbstractClass<object>) => RemoveAbstractFromImplClass<
|
// apply as unknown as (Super: AbstractClass<object>) => RemoveAbstractFromImplClass<
|
||||||
ImplClassWithAbstract,
|
// ImplClassWithAbstract,
|
||||||
ExtendAbstractSuper<SuperExpression, Abstract>,
|
// ExtendAbstractSuper<SuperExpression, Abstract>,
|
||||||
ExtendStaticAbstractSuper<SuperExpression, StaticAbstract>
|
// ExtendStaticAbstractSuper<SuperExpression, StaticAbstract>
|
||||||
>,
|
// >,
|
||||||
|
apply as unknown as (Super: AbstractClass<object>) => ImplClassWithAbstract,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
20
src/tests.ts
20
src/tests.ts
@@ -1,7 +1,8 @@
|
|||||||
import { TraitClass } from "./Trait"
|
import { Trait, TraitClass } from "./Trait"
|
||||||
import { trait } from "./TraitBuilder"
|
import { trait } from "./TraitBuilder"
|
||||||
import { Implements, ImplementsStatic } from "./TraitExpression"
|
import { Implements, ImplementsStatic, TraitExpression } from "./TraitExpression"
|
||||||
import { expression } from "./TraitExpressionBuilder"
|
import { expression } from "./TraitExpressionBuilder"
|
||||||
|
import { ExtendPlain } from "./util"
|
||||||
|
|
||||||
|
|
||||||
const PrintsHelloOnNew = trait
|
const PrintsHelloOnNew = trait
|
||||||
@@ -80,3 +81,18 @@ class User extends exp.extends implements Implements<typeof exp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(new User())
|
console.log(new User())
|
||||||
|
|
||||||
|
|
||||||
|
type ExpectsObjectArray<T extends readonly object[]> = T
|
||||||
|
|
||||||
|
type Maps<T extends readonly any[]> = {
|
||||||
|
[K in keyof T]: T[K]
|
||||||
|
}
|
||||||
|
|
||||||
|
type MapTraits<Exp extends TraitExpression<any, any>> = (
|
||||||
|
ExpectsObjectArray<
|
||||||
|
Maps<
|
||||||
|
|
||||||
|
>
|
||||||
|
>
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user