Refactoring
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Julien Valverdé
2024-02-16 01:14:36 +01:00
parent af8884cdee
commit 9f2c42db14
2 changed files with 63 additions and 61 deletions

View File

@@ -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
]>
)