This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Fn, Pipe, Tuples } from "hotscript"
|
||||
import { AbstractClass, Class, Simplify } from "type-fest"
|
||||
import { Trait, Traits } from "./Trait"
|
||||
import { Trait, TraitInstance, Traits } from "./Trait"
|
||||
import { TraitBuilder } from "./TraitBuilder"
|
||||
import { ExtendFn, ExtendPlain, SimplifyFn, StaticMembersFn } from "./util"
|
||||
|
||||
@@ -49,22 +49,22 @@ export class TraitExpression<
|
||||
) {
|
||||
return new TraitBuilder<
|
||||
This,
|
||||
|
||||
Simplify<
|
||||
ExtendPlain<Traits.MapAbstract<T>>
|
||||
>,
|
||||
Simplify<
|
||||
ExtendPlain<Traits.MapStaticAbstract<T>>
|
||||
>,
|
||||
(
|
||||
AbstractClass<
|
||||
Simplify<
|
||||
ExtendPlain<Traits.MapImplInstance<T>>
|
||||
>
|
||||
> &
|
||||
|
||||
AbstractClass<
|
||||
Simplify<
|
||||
ExtendPlain<Traits.MapImplStaticMembers<T>>
|
||||
ExtendPlain<Traits.MapImplInstance<T>>
|
||||
>
|
||||
)
|
||||
> &
|
||||
Simplify<
|
||||
ExtendPlain<Traits.MapImplStaticMembers<T>>
|
||||
>
|
||||
>(
|
||||
this,
|
||||
{} as any,
|
||||
@@ -100,26 +100,34 @@ export namespace TraitExpression {
|
||||
}
|
||||
|
||||
|
||||
export type Implements<Exp extends TraitExpression<any, any>> = (
|
||||
Pipe<Exp, [
|
||||
TraitExpression.TraitsFn,
|
||||
Tuples.Map<Trait.OwnAbstractFn>,
|
||||
ExtendFn,
|
||||
SimplifyFn,
|
||||
]>
|
||||
export type Implements<
|
||||
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||
> = (
|
||||
Simplify<
|
||||
ExtendPlain<
|
||||
Traits.MapAbstract<
|
||||
TraitExpression.Traits<Exp>
|
||||
>
|
||||
>
|
||||
>
|
||||
)
|
||||
|
||||
export type ImplementsStatic<Exp extends TraitExpression<any, any>> = (
|
||||
Pipe<Exp, [
|
||||
TraitExpression.TraitsFn,
|
||||
Tuples.Map<Trait.OwnStaticAbstractFn>,
|
||||
ExtendFn,
|
||||
SimplifyFn,
|
||||
]>
|
||||
export type ImplementsStatic<
|
||||
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||
> = (
|
||||
Simplify<
|
||||
ExtendPlain<
|
||||
Traits.MapStaticAbstract<
|
||||
TraitExpression.Traits<Exp>
|
||||
>
|
||||
>
|
||||
>
|
||||
)
|
||||
|
||||
|
||||
export type TraitExpressionClass<Exp extends TraitExpression<any, any>> = (
|
||||
export type TraitExpressionClass<
|
||||
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||
> = (
|
||||
AbstractClass<
|
||||
TraitExpressionInstance<Exp>,
|
||||
ConstructorParameters<TraitExpression.Superclass<Exp>>
|
||||
@@ -127,7 +135,9 @@ export type TraitExpressionClass<Exp extends TraitExpression<any, any>> = (
|
||||
TraitExpressionStaticMembers<Exp>
|
||||
)
|
||||
|
||||
export type TraitExpressionConcreteClass<Exp extends TraitExpression<any, any>> = (
|
||||
export type TraitExpressionConcreteClass<
|
||||
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||
> = (
|
||||
Class<
|
||||
TraitExpressionInstance<Exp>,
|
||||
ConstructorParameters<TraitExpression.Superclass<Exp>>
|
||||
@@ -135,18 +145,35 @@ export type TraitExpressionConcreteClass<Exp extends TraitExpression<any, any>>
|
||||
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 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>
|
||||
>,
|
||||
]>
|
||||
>
|
||||
)
|
||||
type MapTraitsInstance<T extends Trait<any, any, any, any>[]> = {
|
||||
[K in keyof T]: K extends keyof []
|
||||
? T[K]
|
||||
: TraitInstance<T[K]>
|
||||
}
|
||||
|
||||
export type TraitExpressionStaticMembers<Exp extends TraitExpression<any, any>> = (
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user