diff --git a/bun.lockb b/bun.lockb index ccc9e1c..fa6b0f8 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 1c12030..d42c433 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@thilawyn/traitify-ts", - "version": "0.1.23", + "version": "0.1.24", "type": "module", "publishConfig": { "registry": "https://git.jvalver.de/api/packages/thilawyn/npm/" @@ -30,12 +30,12 @@ "default": "./dist/effect/lib.cjs" } }, - "./traitsUnique-h-N6REho": { + "./traitsUnique-DCJN7XEW": { "import": { - "types": "./dist/traitsUnique-h-N6REho.d.ts" + "types": "./dist/traitsUnique-DCJN7XEW.d.ts" }, "require": { - "types": "./dist/traitsUnique-h-N6REho.d.ts" + "types": "./dist/traitsUnique-DCJN7XEW.d.ts" } } }, @@ -55,7 +55,7 @@ "npm-check-updates": "^16.14.20", "npm-sort": "^0.0.4", "tsup": "^8.0.2", - "tsx": "^4.10.0", + "tsx": "^4.10.1", "typescript": "^5.4.5" }, "optionalDependencies": { diff --git a/src/TraitBuilder.ts b/src/TraitBuilder.ts index 6be7003..29a8cbc 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 @@ -24,8 +24,19 @@ export class TraitBuilder< ) {} - abstract( - _: (Super: AbstractConstructor) => AbstractConstructor + abstract & StaticAbstract>( + _: (Super: AbstractConstructor & StaticAbstract) => A + ) { + return new TraitBuilder( + this.traitSuperExpression, + {} as Simplify>, + {} as Simplify>, + this.traitApply, + ) + } + + abstractType( + _: (Super: Abstract) => typeof type ) { return new TraitBuilder( this.traitSuperExpression, @@ -35,8 +46,8 @@ export class TraitBuilder< ) } - staticAbstract( - _: (Super: AbstractConstructor) => AbstractConstructor + staticAbstractType( + _: (Super: StaticAbstract) => typeof type ) { return new TraitBuilder( this.traitSuperExpression, @@ -163,7 +174,7 @@ export function implStaticInstantiableThis< export const trait = new TraitBuilder( new TraitExpression(TraitExpression.NullSuperclass, []), - {} as object, - {} as object, - Super => class extends Super {} as AbstractConstructor, + {} as {}, + {} as {}, + Super => class extends Super {} as AbstractConstructor<{}>, ) diff --git a/src/TraitExpression.ts b/src/TraitExpression.ts index 0021168..75b655e 100644 --- a/src/TraitExpression.ts +++ b/src/TraitExpression.ts @@ -142,7 +142,7 @@ export type TraitExpressionClass< TraitExpressionStaticMembers ) -export type TraitExpressionConcreteClass< +export type TraitExpressionInstantiableClass< Exp extends TraitExpressionLike[]> > = ( Constructor< diff --git a/src/effect/EffectSchemaTraitExpression.ts b/src/effect/EffectSchemaTraitExpression.ts index 2d284f8..707e6ac 100644 --- a/src/effect/EffectSchemaTraitExpression.ts +++ b/src/effect/EffectSchemaTraitExpression.ts @@ -32,17 +32,14 @@ implements TraitExpressionLike< extends(): ( AbstractConstructor< - ApplyMutability, Mutability> & - Omit< - Simplify< - Extend<[ - Inherited, - ...TraitTuple.MapImplInstance - ]> - >, - keyof Fields - > & - Proto, + Simplify< + ApplyMutability, Mutability> & + Extend<[ + Omit, + ...TraitTuple.MapImplInstance + ]> & + Proto + >, ConstructorParameters> > & @@ -57,7 +54,6 @@ implements TraitExpressionLike< Proto > > & - Simplify< Extend<[ Static, diff --git a/src/lib.ts b/src/lib.ts index a96aa6a..0bd4637 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,4 +1,5 @@ export { Trait, TraitClass, TraitConcreteClass, TraitInstance, TraitStaticMembers, TraitTuple } from "./Trait" export { ImplStatic, TraitBuilder, implStaticInstantiableThis, implStaticThis, trait } from "./TraitBuilder" -export { Implements, StaticImplements, TraitExpression, TraitExpressionClass, TraitExpressionConcreteClass, TraitExpressionInstance, TraitExpressionStaticMembers } from "./TraitExpression" +export { Implements, StaticImplements, TraitExpression, TraitExpressionClass, TraitExpressionInstance, TraitExpressionInstantiableClass, TraitExpressionStaticMembers } from "./TraitExpression" export { TraitExpressionBuilder, expression } from "./TraitExpressionBuilder" +export { type } from "./util" 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..c83e71c 100644 --- a/src/util/misc.ts +++ b/src/util/misc.ts @@ -12,6 +12,6 @@ export type CommonKeys = Extract * Represents the static members of a class. * @template Class - A class. */ -export type StaticMembers> = ( - Omit -) +export type StaticMembers> = Omit + +export function type() { return {} as T }