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

This commit is contained in:
Julien Valverdé
2024-02-03 23:15:30 +01:00
parent 8af604831b
commit 0d469fabeb
2 changed files with 19 additions and 8 deletions

View File

@@ -28,17 +28,27 @@ type RemoveAbstractFromImpl<
export class Trait<
Abstract extends {},
Impl extends Class<{}, []>,
Abstract extends {},
Impl extends Class<{}, []>,
Supertraits extends Trait<any, any, any>[]
> {
constructor(
readonly abstract: Abstract,
readonly apply: (Super: AbstractClass<{}>) => Impl,
readonly supertraits: Supertraits,
readonly ownAbstract: Abstract,
readonly apply: (Super: AbstractClass<{}>) => Impl,
) {}
}
export interface Trait<
Abstract extends {},
Impl extends Class<{}, []>,
Supertraits extends Trait<any, any, any>[]
> {
get ownImplClass(): Impl
}
export type TraitAbstractMembers<T> = (
T extends Trait<infer AbstractMembers, any>
T extends Trait<infer AbstractMembers, any, any>
? AbstractMembers
: never
)
@@ -48,7 +58,7 @@ export interface TraitAbstractMembersFn extends Fn {
}
export type TraitImplClass<T> = (
T extends Trait<any, infer Impl>
T extends Trait<any, infer Impl, any>
? Impl
: never
)
@@ -102,6 +112,7 @@ export function trait<
),
) {
return new Trait(
[] as const,
abstract as Abstract,
apply as any as (Super: AbstractClass<{}>) => RemoveAbstractFromImpl<ImplWithAbstract, Abstract>,
)