This commit is contained in:
23
src/trait.ts
23
src/trait.ts
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user