0.1.3 (#3)
All checks were successful
continuous-integration/drone/push Build is passing

Co-authored-by: Julien Valverdé <julien.valverde@mailo.com>
Reviewed-on: https://git.jvalver.de/Thilawyn/traitify-ts/pulls/3
This commit was merged in pull request #3.
This commit is contained in:
Julien Valverdé
2024-02-08 20:01:16 +01:00
parent 98fbed09b3
commit c1c3c07524
10 changed files with 93 additions and 111 deletions

View File

@@ -1,9 +1,13 @@
import { Fn, Pipe, Tuples } from "hotscript"
import { AbstractClass, Class, Opaque } from "type-fest"
import { AbstractTag, TraitExpression, emptyTraitExpression } from "."
import { TraitExpression, emptyTraitExpression } from "./TraitExpression"
import { AbstractTag } from "./abstract"
import { ExtendFn, SimplifyFn, StaticMembers, StaticMembersFn } from "./util"
export type TraitApplierSuperTag = "@thilawyn/traitify-ts/TraitApplierSuper"
export type AddAbstractToImplClass<
ImplClass extends Class<{}, []>,
Abstract extends {},
@@ -16,14 +20,14 @@ export type AddAbstractToImplClass<
)
export type RemoveAbstractFromImplClass<
ImplClassWithAbstract extends Class<Abstract, []>,
ImplClassWithAbstract extends Class<Abstract, []> & { _tag: TraitApplierSuperTag },
Abstract extends {},
> = (
Class<
Omit<InstanceType<ImplClassWithAbstract>, keyof Abstract>,
ConstructorParameters<ImplClassWithAbstract>
> &
StaticMembers<ImplClassWithAbstract>
Omit<StaticMembers<ImplClassWithAbstract>, "_tag">
)
@@ -110,7 +114,9 @@ export namespace Trait {
Trait.Instance<T>,
any[]
> &
Pipe<[...Trait.Supertraits<T>, T], [
Pipe<T, [
Trait.SupertraitsFn,
Tuples.Append<T>,
Tuples.Map<Trait.OwnClassFn>,
Tuples.Map<StaticMembersFn>,
ExtendFn,
@@ -122,7 +128,9 @@ export namespace Trait {
}
export type Instance<T> = (
Pipe<[...Trait.Supertraits<T>, T], [
Pipe<T, [
Trait.SupertraitsFn,
Tuples.Append<T>,
Tuples.Map<Trait.OwnInstanceFn>,
ExtendFn,
SimplifyFn,
@@ -134,16 +142,12 @@ export namespace Trait {
}
export type TraitApplierSuperTag = "@thilawyn/traitify-ts/TraitApplierSuper"
export function trait<
Abstract extends {},
ImplClassWithAbstract extends Class<Abstract, []>,
ImplClassWithAbstract extends Class<Abstract, []> & { _tag: TraitApplierSuperTag },
>(
abstract: Opaque<Abstract, AbstractTag>,
apply: (Super: Opaque<AbstractClass<Abstract>, TraitApplierSuperTag>) => (
Opaque<ImplClassWithAbstract, TraitApplierSuperTag>
),
abstract: Opaque<Abstract, AbstractTag>,
apply: (Super: AbstractClass<Abstract> & { _tag: TraitApplierSuperTag }) => ImplClassWithAbstract,
) {
return new Trait(
emptyTraitExpression,