Trait applier super tag as symbol
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -39,6 +39,6 @@ export const createBundleConfig = (
|
|||||||
|
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
createBundleConfig("src/lib.ts", "."),
|
createBundleConfig("src/index.ts", "."),
|
||||||
createBundleConfig("src/util/lib.ts", "./util"),
|
createBundleConfig("src/util/lib.ts", "./util"),
|
||||||
]
|
]
|
||||||
|
|||||||
12
src/Trait.ts
12
src/Trait.ts
@@ -1,10 +1,12 @@
|
|||||||
import { Fn, Pipe, Tuples } from "hotscript"
|
import { Fn, Pipe, Tuples } from "hotscript"
|
||||||
import { AbstractClass, Class, Opaque } from "type-fest"
|
import { AbstractClass, Class, Opaque } from "type-fest"
|
||||||
import { tag } from "type-fest/source/opaque"
|
|
||||||
import { AbstractTag, TraitExpression, emptyTraitExpression } from "."
|
import { AbstractTag, TraitExpression, emptyTraitExpression } from "."
|
||||||
import { ExtendFn, SimplifyFn, StaticMembers, StaticMembersFn } from "./util"
|
import { ExtendFn, SimplifyFn, StaticMembers, StaticMembersFn } from "./util"
|
||||||
|
|
||||||
|
|
||||||
|
export const isTraitApplierSuper = Symbol("isTraitApplierSuper")
|
||||||
|
|
||||||
|
|
||||||
export type AddAbstractToImplClass<
|
export type AddAbstractToImplClass<
|
||||||
ImplClass extends Class<{}, []>,
|
ImplClass extends Class<{}, []>,
|
||||||
Abstract extends {},
|
Abstract extends {},
|
||||||
@@ -17,14 +19,14 @@ export type AddAbstractToImplClass<
|
|||||||
)
|
)
|
||||||
|
|
||||||
export type RemoveAbstractFromImplClass<
|
export type RemoveAbstractFromImplClass<
|
||||||
ImplClassWithAbstract extends Opaque<Class<Abstract, []>, TraitApplierSuperTag>,
|
ImplClassWithAbstract extends Class<Abstract, []> & { [isTraitApplierSuper]: true },
|
||||||
Abstract extends {},
|
Abstract extends {},
|
||||||
> = (
|
> = (
|
||||||
Class<
|
Class<
|
||||||
Omit<InstanceType<ImplClassWithAbstract>, keyof Abstract>,
|
Omit<InstanceType<ImplClassWithAbstract>, keyof Abstract>,
|
||||||
ConstructorParameters<ImplClassWithAbstract>
|
ConstructorParameters<ImplClassWithAbstract>
|
||||||
> &
|
> &
|
||||||
Omit<StaticMembers<ImplClassWithAbstract>, typeof tag>
|
Omit<StaticMembers<ImplClassWithAbstract>, typeof isTraitApplierSuper>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -139,10 +141,10 @@ export type TraitApplierSuperTag = "@thilawyn/traitify-ts/TraitApplierSuper"
|
|||||||
|
|
||||||
export function trait<
|
export function trait<
|
||||||
Abstract extends {},
|
Abstract extends {},
|
||||||
ImplClassWithAbstract extends Opaque<Class<Abstract, []>, TraitApplierSuperTag>,
|
ImplClassWithAbstract extends Class<Abstract, []> & { [isTraitApplierSuper]: true },
|
||||||
>(
|
>(
|
||||||
abstract: Opaque<Abstract, AbstractTag>,
|
abstract: Opaque<Abstract, AbstractTag>,
|
||||||
apply: (Super: Opaque<AbstractClass<Abstract>, TraitApplierSuperTag>) => ImplClassWithAbstract,
|
apply: (Super: AbstractClass<Abstract> & { [isTraitApplierSuper]: true }) => ImplClassWithAbstract,
|
||||||
) {
|
) {
|
||||||
return new Trait(
|
return new Trait(
|
||||||
emptyTraitExpression,
|
emptyTraitExpression,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Call, Fn, Pipe, Tuples } from "hotscript"
|
import { Call, Fn, Pipe, Tuples } from "hotscript"
|
||||||
import { AbstractClass, Class, Opaque } from "type-fest"
|
import { AbstractClass, Class, Opaque } from "type-fest"
|
||||||
import { AbstractTag, RemoveAbstractFromImplClass, Trait, TraitApplierSuperTag } from "."
|
import { AbstractTag, RemoveAbstractFromImplClass, Trait, TraitApplierSuperTag, isTraitApplierSuper } from "."
|
||||||
import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util"
|
import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util"
|
||||||
|
|
||||||
|
|
||||||
@@ -53,11 +53,11 @@ export class TraitExpression<
|
|||||||
subtrait<
|
subtrait<
|
||||||
This extends TraitExpression<typeof TraitExpression.NullSuperclass, any, any>,
|
This extends TraitExpression<typeof TraitExpression.NullSuperclass, any, any>,
|
||||||
SubtraitAbstract extends Implements<This>,
|
SubtraitAbstract extends Implements<This>,
|
||||||
SubtraitImplClassWithAbstract extends Opaque<Class<SubtraitAbstract, []>, TraitApplierSuperTag>,
|
SubtraitImplClassWithAbstract extends Class<SubtraitAbstract, []> & { [isTraitApplierSuper]: true },
|
||||||
>(
|
>(
|
||||||
this: This,
|
this: This,
|
||||||
abstract: (expression: This) => Opaque<SubtraitAbstract, AbstractTag>,
|
abstract: (expression: This) => Opaque<SubtraitAbstract, AbstractTag>,
|
||||||
apply: (Super: Opaque<AbstractClass<SubtraitAbstract>, TraitApplierSuperTag>) => SubtraitImplClassWithAbstract,
|
apply: (Super: AbstractClass<SubtraitAbstract> & { [isTraitApplierSuper]: true }) => SubtraitImplClassWithAbstract,
|
||||||
) {
|
) {
|
||||||
return new Trait(
|
return new Trait(
|
||||||
this,
|
this,
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ export {
|
|||||||
trait,
|
trait,
|
||||||
type Trait,
|
type Trait,
|
||||||
type TraitExpression,
|
type TraitExpression,
|
||||||
|
isTraitApplierSuper,
|
||||||
} from "."
|
} from "."
|
||||||
|
|||||||
Reference in New Issue
Block a user