This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Fn, Pipe, Tuples } from "hotscript"
|
||||
import { AbstractClass } from "type-fest"
|
||||
import { AbstractClass, Class } from "type-fest"
|
||||
import { Trait } from "./Trait"
|
||||
import { TraitBuilder } from "./TraitBuilder"
|
||||
import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util"
|
||||
@@ -59,6 +59,7 @@ export class TraitExpression<
|
||||
export namespace TraitExpression {
|
||||
export class NullSuperclass {
|
||||
static readonly _tag = "@thilawyn/traitify-ts/TraitExpression.NullSuperclass"
|
||||
constructor(...args: any[]) {}
|
||||
}
|
||||
|
||||
export type Superclass<T> = (
|
||||
@@ -102,25 +103,37 @@ export type ImplementsStatic<Exp extends TraitExpression<any, any>> = (
|
||||
|
||||
export type TraitExpressionClass<Exp extends TraitExpression<any, any>> = (
|
||||
AbstractClass<
|
||||
TraitExpressionInstance<Exp>,
|
||||
ConstructorParameters<TraitExpression.Superclass<Exp>>
|
||||
> &
|
||||
|
||||
|
||||
TraitExpressionStaticMembers<Exp>
|
||||
)
|
||||
|
||||
export type TraitExpressionConcreteClass<Exp extends TraitExpression<any, any>> = (
|
||||
|
||||
Class<
|
||||
TraitExpressionInstance<Exp>,
|
||||
ConstructorParameters<TraitExpression.Superclass<Exp>>
|
||||
> &
|
||||
TraitExpressionStaticMembers<Exp>
|
||||
)
|
||||
|
||||
export type TraitExpressionInstance<Exp extends TraitExpression<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
|
||||
]>
|
||||
)
|
||||
|
||||
export type TraitExpressionStaticMembers<Exp extends TraitExpression<any, any>> = (
|
||||
Pipe<Traits, [
|
||||
Tuples.Map<Trait.OwnClassFn>, // Map all the traits to their implementation class
|
||||
Tuples.Prepend<Superclass>, // 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
|
||||
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
|
||||
]>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user