This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Fn, Pipe, Tuples } from "hotscript"
|
||||
import { AbstractClass, Class, Simplify } from "type-fest"
|
||||
import { Trait, TraitInstance, Traits } from "./Trait"
|
||||
import { Trait, TraitInstance, TraitStaticMembers, Traits } from "./Trait"
|
||||
import { TraitBuilder } from "./TraitBuilder"
|
||||
import { ExtendFn, ExtendPlain, SimplifyFn, StaticMembersFn } from "./util"
|
||||
import { ExtendFn, ExtendPlain, SimplifyFn, StaticMembers, StaticMembersFn } from "./util"
|
||||
|
||||
|
||||
export class TraitExpression<
|
||||
@@ -148,37 +148,35 @@ export type TraitExpressionConcreteClass<
|
||||
export type TraitExpressionInstance<
|
||||
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||
> = (
|
||||
// Pipe<TraitExpression.Traits<Exp>, [
|
||||
// Tuples.Map<Trait.OwnInstanceFn>, // Map all the traits to their instance representation
|
||||
// Tuples.Prepend< // Add the instance of the superclass at the top of the list
|
||||
// InstanceType<TraitExpression.Superclass<Exp>>
|
||||
// >,
|
||||
// ExtendFn, // Reduce to a single object that extends all the objects in the list
|
||||
// SimplifyFn, // Make readable for IDEs
|
||||
// ]>
|
||||
Simplify<
|
||||
ExtendPlain<[
|
||||
InstanceType<TraitExpression.Superclass<Exp>>,
|
||||
...MapTraitsInstance<
|
||||
TraitExpression.Traits<Exp>
|
||||
>,
|
||||
...MapTraitsInstance<TraitExpression.Traits<Exp>>,
|
||||
]>
|
||||
>
|
||||
)
|
||||
type MapTraitsInstance<T extends Trait<any, any, any, any>[]> = {
|
||||
type MapTraitsInstance<T> = {
|
||||
[K in keyof T]: K extends keyof []
|
||||
? T[K]
|
||||
: TraitInstance<T[K]>
|
||||
: T[K] extends Trait<any, any, any, any>
|
||||
? TraitInstance<T[K]>
|
||||
: never
|
||||
}
|
||||
|
||||
export type TraitExpressionStaticMembers<
|
||||
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||
> = (
|
||||
Pipe<TraitExpression.Traits<Exp>, [
|
||||
Tuples.Map<Trait.OwnClassFn>, // Map all the traits to their class representation
|
||||
Tuples.Prepend<TraitExpression.Superclass<Exp>>, // Add the superclass at the top of the list
|
||||
Tuples.Map<StaticMembersFn>, // Map all the classes to an object containing their static members
|
||||
ExtendFn, // Reduce to a single object that extends all the objects in the list
|
||||
SimplifyFn, // Make readable for IDEs
|
||||
Simplify<
|
||||
ExtendPlain<[
|
||||
StaticMembers<TraitExpression.Superclass<Exp>>,
|
||||
...MapTraitsStaticMembers<TraitExpression.Traits<Exp>>,
|
||||
]>
|
||||
>
|
||||
)
|
||||
type MapTraitsStaticMembers<T> = {
|
||||
[K in keyof T]: K extends keyof []
|
||||
? T[K]
|
||||
: T[K] extends Trait<any, any, any, any>
|
||||
? TraitStaticMembers<T[K]>
|
||||
: never
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TraitClass } from "./Trait"
|
||||
import { trait } from "./TraitBuilder"
|
||||
import { Implements, ImplementsStatic } from "./TraitExpression"
|
||||
import { Implements, ImplementsStatic, TraitExpressionClass } from "./TraitExpression"
|
||||
import { expression } from "./TraitExpressionBuilder"
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ const exp = expression
|
||||
|
||||
type Abs = Implements<typeof exp>
|
||||
type AbsStatic = ImplementsStatic<typeof exp>
|
||||
type ExpClass = TraitExpressionClass<typeof exp>
|
||||
|
||||
@exp.implementsStatic
|
||||
class User extends exp.extends implements Implements<typeof exp> {
|
||||
|
||||
Reference in New Issue
Block a user