0.1.24 #24

Merged
Thilawyn merged 8 commits from next into master 2024-05-13 01:25:26 +02:00
3 changed files with 32 additions and 4 deletions
Showing only changes of commit af45a26c73 - Show all commits

View File

@@ -1,7 +1,7 @@
import { AbstractConstructor, Constructor, Simplify } from "type-fest"
import { Trait } from "./Trait"
import { TraitExpression } from "./TraitExpression"
import { Extend, StaticMembers } from "./util"
import { Extend, StaticMembers, type } from "./util"
declare const implSuperSymbol: unique symbol
@@ -35,6 +35,17 @@ export class TraitBuilder<
)
}
abstractType<A extends Abstract>(
_: (Super: Abstract) => typeof type<A>
) {
return new TraitBuilder(
this.traitSuperExpression,
{} as Simplify<A>,
this.traitStaticAbstract,
this.traitApply,
)
}
staticAbstract<A extends StaticAbstract>(
_: (Super: AbstractConstructor<StaticAbstract>) => AbstractConstructor<A, []>
) {
@@ -46,6 +57,17 @@ export class TraitBuilder<
)
}
staticAbstractType<A extends StaticAbstract>(
_: (Super: StaticAbstract) => typeof type<A>
) {
return new TraitBuilder(
this.traitSuperExpression,
this.traitAbstract,
{} as Simplify<A>,
this.traitApply,
)
}
implement<
ImplClassWithAbstract extends TraitBuilder.ImplSuper<typeof this> // TODO: find a way to set the constraint to concrete classes while keeping the Super arg as an abstract class
>(

View File

@@ -2,6 +2,7 @@ import { TraitClass } from "./Trait"
import { trait } from "./TraitBuilder"
import { Implements, StaticImplements, TraitExpressionClass } from "./TraitExpression"
import { expression } from "./TraitExpressionBuilder"
import { type } from "./util"
const PrintsHelloOnNew = trait
@@ -18,9 +19,12 @@ const PrintsHelloOnNew = trait
type PrintsHelloOnNewClass = TraitClass<typeof PrintsHelloOnNew>
const Identifiable = <ID>() => trait
.abstract(Super => class extends Super {
declare readonly id: ID
})
// .abstract(Super => class extends Super {
// declare readonly id: ID
// })
.abstractType(Super => type<typeof Super & {
readonly id: ID
}>)
.implement(Super => class Identifiable extends Super {
equals(el: Identifiable) {
return this.id === el.id

View File

@@ -15,3 +15,5 @@ export type CommonKeys<A, B> = Extract<keyof A, keyof B>
export type StaticMembers<Class extends AbstractConstructor<any>> = (
Omit<Class, "prototype">
)
export function type<T>() { return {} as T }