diff --git a/src/Trait.ts b/src/Trait.ts index f340371..886fb77 100644 --- a/src/Trait.ts +++ b/src/Trait.ts @@ -69,24 +69,6 @@ export namespace Trait { StaticMembers> ) - export type OwnClass = ( - AbstractClass, any[]> & - Extend<[ - Trait.OwnStaticAbstract, - StaticMembers>, - ]> - ) - export interface OwnClassFn extends Fn { - return: Trait.OwnClass - } - - export type OwnInstance = ( - Extend<[Trait.OwnAbstract, Trait.OwnImplInstance]> - ) - export interface OwnInstanceFn extends Fn { - return: Trait.OwnInstance - } - export type Supertraits = ( TraitExpression.Traits> ) diff --git a/src/TraitExpression.ts b/src/TraitExpression.ts index 46e912a..3c3a5fb 100644 --- a/src/TraitExpression.ts +++ b/src/TraitExpression.ts @@ -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> >, Simplify< ExtendPlain> >, - ( - AbstractClass< - Simplify< - ExtendPlain> - > - > & + + AbstractClass< Simplify< - ExtendPlain> + ExtendPlain> > - ) + > & + Simplify< + ExtendPlain> + > >( this, {} as any, @@ -100,26 +100,34 @@ export namespace TraitExpression { } -export type Implements> = ( - Pipe, - ExtendFn, - SimplifyFn, - ]> +export type Implements< + Exp extends TraitExpression[]> +> = ( + Simplify< + ExtendPlain< + Traits.MapAbstract< + TraitExpression.Traits + > + > + > ) -export type ImplementsStatic> = ( - Pipe, - ExtendFn, - SimplifyFn, - ]> +export type ImplementsStatic< + Exp extends TraitExpression[]> +> = ( + Simplify< + ExtendPlain< + Traits.MapStaticAbstract< + TraitExpression.Traits + > + > + > ) -export type TraitExpressionClass> = ( +export type TraitExpressionClass< + Exp extends TraitExpression[]> +> = ( AbstractClass< TraitExpressionInstance, ConstructorParameters> @@ -127,7 +135,9 @@ export type TraitExpressionClass> = ( TraitExpressionStaticMembers ) -export type TraitExpressionConcreteClass> = ( +export type TraitExpressionConcreteClass< + Exp extends TraitExpression[]> +> = ( Class< TraitExpressionInstance, ConstructorParameters> @@ -135,18 +145,35 @@ export type TraitExpressionConcreteClass> TraitExpressionStaticMembers ) -export type TraitExpressionInstance> = ( - Pipe, [ - Tuples.Map, // Map all the traits to their instance representation - Tuples.Prepend< // Add the instance of the superclass at the top of the list - InstanceType> - >, - 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[]> +> = ( + // Pipe, [ + // Tuples.Map, // Map all the traits to their instance representation + // Tuples.Prepend< // Add the instance of the superclass at the top of the list + // InstanceType> + // >, + // ExtendFn, // Reduce to a single object that extends all the objects in the list + // SimplifyFn, // Make readable for IDEs + // ]> + Simplify< + ExtendPlain<[ + InstanceType>, + ...MapTraitsInstance< + TraitExpression.Traits + >, + ]> + > ) +type MapTraitsInstance[]> = { + [K in keyof T]: K extends keyof [] + ? T[K] + : TraitInstance +} -export type TraitExpressionStaticMembers> = ( +export type TraitExpressionStaticMembers< + Exp extends TraitExpression[]> +> = ( Pipe, [ Tuples.Map, // Map all the traits to their class representation Tuples.Prepend>, // Add the superclass at the top of the list