diff --git a/src/TraitBuilder.ts b/src/TraitBuilder.ts index 6be7003..2f129f8 100644 --- a/src/TraitBuilder.ts +++ b/src/TraitBuilder.ts @@ -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( + _: (Super: Abstract) => typeof type + ) { + return new TraitBuilder( + this.traitSuperExpression, + {} as Simplify, + this.traitStaticAbstract, + this.traitApply, + ) + } + staticAbstract( _: (Super: AbstractConstructor) => AbstractConstructor ) { @@ -46,6 +57,17 @@ export class TraitBuilder< ) } + staticAbstractType( + _: (Super: StaticAbstract) => typeof type + ) { + return new TraitBuilder( + this.traitSuperExpression, + this.traitAbstract, + {} as Simplify, + this.traitApply, + ) + } + implement< ImplClassWithAbstract extends TraitBuilder.ImplSuper // TODO: find a way to set the constraint to concrete classes while keeping the Super arg as an abstract class >( diff --git a/src/tests.ts b/src/tests.ts index 7d7278c..61f3fdd 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -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 const Identifiable = () => trait - .abstract(Super => class extends Super { - declare readonly id: ID - }) + // .abstract(Super => class extends Super { + // declare readonly id: ID + // }) + .abstractType(Super => type) .implement(Super => class Identifiable extends Super { equals(el: Identifiable) { return this.id === el.id diff --git a/src/util/misc.ts b/src/util/misc.ts index c2a1306..85b4f9b 100644 --- a/src/util/misc.ts +++ b/src/util/misc.ts @@ -15,3 +15,5 @@ export type CommonKeys = Extract export type StaticMembers> = ( Omit ) + +export function type() { return {} as T }