From b2eae567c4f82a71b70783102b626b7715aad83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 13 May 2024 01:25:25 +0200 Subject: [PATCH] 0.1.24 (#24) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Julien Valverdé Reviewed-on: https://git.jvalver.de/Thilawyn/traitify-ts/pulls/24 --- bun.lockb | Bin 160474 -> 160474 bytes package.json | 10 ++++---- src/TraitBuilder.ts | 27 +++++++++++++++------- src/TraitExpression.ts | 2 +- src/effect/EffectSchemaTraitExpression.ts | 20 +++++++--------- src/lib.ts | 3 ++- src/tests.ts | 10 +++++--- src/util/misc.ts | 6 ++--- 8 files changed, 45 insertions(+), 33 deletions(-) diff --git a/bun.lockb b/bun.lockb index ccc9e1c91efc1a03ee0f8412d0910640344a7e0b..fa6b0f87218008962037e7e50917758cb2c5bfb5 100755 GIT binary patch delta 144 zcmV;B0B`@=3Z6DXP-xpz0Q;Bg^lu}+#B zljtQdvltw`gFqYLoXIn&rwDE%%|%n(0rx)vF}Fqc0hN2pI6ck) delta 148 zcmV;F0Bir+T=@w7MLo7$9uL4~?~D%AfVo=$nHTptlvE0XG)`Ft<&&0rx)vFt( - _: (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 }