Trait refactoring
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Julien Valverdé
2024-02-03 02:18:36 +01:00
parent 3c40a0a96b
commit c1097ff2f2
3 changed files with 43 additions and 33 deletions

View File

@@ -1,6 +1,7 @@
import { Fn } from "hotscript"
import { AbstractClass, Class, Opaque } from "type-fest"
import { StaticMembers } from "./util"
import { AbstractTag } from "."
type AddAbstractToImpl<
@@ -105,14 +106,16 @@ export type TraitApplier<
)
export function trait<
Abstract extends object = {}
>(): (
<ImplWithAbstract extends Class<Abstract, []>>(
apply: TraitApplier<Abstract, ImplWithAbstract>
) => Trait<
Abstract,
RemoveAbstractFromImpl<ImplWithAbstract, Abstract>
>
) {
return apply => ({ apply }) as any
Abstract extends {},
ImplWithAbstract extends Class<Abstract, []>,
>(
abstract: Opaque<Abstract, AbstractTag>,
apply: (Super: Opaque<AbstractClass<Abstract>, TraitApplierSuperTag>) => (
Opaque<ImplWithAbstract, TraitApplierSuperTag>
),
): Trait<
Abstract,
RemoveAbstractFromImpl<ImplWithAbstract, Abstract>
> {
return { apply } as any
}