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

This commit is contained in:
Julien Valverdé
2024-02-19 01:40:24 +01:00
parent 34c91707ae
commit 3c470a63f2

View File

@@ -1,32 +1,34 @@
import { AbstractClass, Simplify } from "type-fest" import { AbstractClass, Simplify } from "type-fest"
import { Trait, Traits } from "./Trait" import { Trait } from "./Trait"
import { TraitExpression } from "./TraitExpression" import { TraitExpression } from "./TraitExpression"
import { ExtendPlain, StaticMembers } from "./util" import { ExtendPlain, StaticMembers } from "./util"
type ImplSuper< type ImplSuper<This> = (
SuperExpression extends TraitExpression< This extends TraitBuilder<
typeof TraitExpression.NullSuperclass, any,
Trait<any, any, any, any>[] infer Abstract,
>, infer StaticAbstract,
Abstract extends object, infer ImplClass
StaticAbstract extends object, >
> = ( ? (
AbstractClass< AbstractClass<
ExtendPlain<[ Simplify<
...Traits.MapImplInstance< ExtendPlain<[
TraitExpression.Traits<SuperExpression> Abstract,
>, InstanceType<ImplClass>,
Abstract, ]>
]> >
> & > &
ExtendPlain<[ Simplify<
...Traits.MapImplStaticMembers< ExtendPlain<[
TraitExpression.Traits<SuperExpression> StaticAbstract,
>, StaticMembers<ImplClass>,
StaticAbstract, ]>
]> & > &
{ readonly _tag: "@thilawyn/traitify-ts/Super" } // TODO: replace with unique symbol? { readonly _tag: "@thilawyn/traitify-ts/Super" } // TODO: replace with unique symbol?
)
: never
) )
@@ -69,15 +71,9 @@ export class TraitBuilder<
} }
implement< implement<
ImplClassWithAbstract extends ImplSuper< // TODO: use This instead? ImplClassWithAbstract extends ImplSuper<typeof this>
SuperExpression,
Abstract,
StaticAbstract
>
>( >(
apply: ( apply: (Super: ImplSuper<typeof this>) => ImplClassWithAbstract
Super: ImplSuper<SuperExpression, Abstract, StaticAbstract>
) => ImplClassWithAbstract
) { ) {
return new TraitBuilder( return new TraitBuilder(
this.traitSuperExpression, this.traitSuperExpression,
@@ -91,9 +87,7 @@ export class TraitBuilder<
InstanceType<ImplClassWithAbstract>, InstanceType<ImplClassWithAbstract>,
keyof Abstract keyof Abstract
> >
>, >
ConstructorParameters<ImplClassWithAbstract>
> & > &
Simplify< Simplify<
Omit< Omit<