Fixed TraitExpression
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Julien Valverdé
2024-02-19 17:07:28 +01:00
parent 4ba0a19037
commit ec82537380

View File

@@ -1,8 +1,7 @@
import { Fn, Pipe, Tuples } from "hotscript"
import { AbstractClass, Class, Simplify } from "type-fest" import { AbstractClass, Class, Simplify } from "type-fest"
import { Trait, TraitInstance, TraitStaticMembers, Traits } from "./Trait" import { Trait, TraitInstance, TraitStaticMembers, Traits } from "./Trait"
import { TraitBuilder } from "./TraitBuilder" import { TraitBuilder } from "./TraitBuilder"
import { ExtendFn, ExtendPlain, SimplifyFn, StaticMembers, StaticMembersFn } from "./util" import { ExtendPlain, StaticMembers } from "./util"
export class TraitExpression< export class TraitExpression<
@@ -16,23 +15,22 @@ export class TraitExpression<
get extends(): ( get extends(): (
AbstractClass< AbstractClass<
Pipe<T, [ Simplify<
Tuples.Map<Trait.OwnImplInstanceFn>, // Map all the traits to the instance of their implementation class ExtendPlain<[
Tuples.Prepend<InstanceType<Superclass>>, // Add the instance of the superclass at the top of the list InstanceType<Superclass>,
ExtendFn, // Reduce to a single instance that extends all the instances in the list ...Traits.MapImplInstance<T>,
SimplifyFn, // Make readable for IDEs ]>
]>, >,
ConstructorParameters<Superclass> ConstructorParameters<Superclass>
> & > &
Pipe<T, [ Simplify<
Tuples.Map<Trait.OwnImplClassFn>, // Map all the traits to their implementation class ExtendPlain<[
Tuples.Prepend<Superclass>, // Add the superclass at the top of the list StaticMembers<Superclass>,
Tuples.Map<StaticMembersFn>, // Map all the classes to an object containing their static members ...Traits.MapImplStaticMembers<T>,
ExtendFn, // Reduce to a single object that extends all the objects in the list ]>
SimplifyFn, // Make readable for IDEs >
]>
) { ) {
return this.traits.reduce( return this.traits.reduce(
(previous, trait) => trait.apply(previous), (previous, trait) => trait.apply(previous),
@@ -85,18 +83,12 @@ export namespace TraitExpression {
? Superclass ? Superclass
: never : never
) )
export interface SuperclassFn extends Fn {
return: TraitExpression.Superclass<this["arg0"]>
}
export type Traits<T> = ( export type Traits<T> = (
T extends TraitExpression<any, infer Traits> T extends TraitExpression<any, infer Traits>
? Traits ? Traits
: never : never
) )
export interface TraitsFn extends Fn {
return: TraitExpression.Traits<this["arg0"]>
}
} }