From c12a80e0072fe56f610dea0d45a7d2b23b6ac6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 12 May 2024 21:03:56 +0200 Subject: [PATCH 1/8] abstractType --- src/lib.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.ts b/src/lib.ts index a96aa6a..7657a81 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -2,3 +2,4 @@ export { Trait, TraitClass, TraitConcreteClass, TraitInstance, TraitStaticMember export { ImplStatic, TraitBuilder, implStaticInstantiableThis, implStaticThis, trait } from "./TraitBuilder" export { Implements, StaticImplements, TraitExpression, TraitExpressionClass, TraitExpressionConcreteClass, TraitExpressionInstance, TraitExpressionStaticMembers } from "./TraitExpression" export { TraitExpressionBuilder, expression } from "./TraitExpressionBuilder" +export { type } from "./util" -- 2.49.1 From af45a26c73b2ca18323eccc247c7a3cea94e35c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 12 May 2024 21:04:02 +0200 Subject: [PATCH 2/8] abstractType --- src/TraitBuilder.ts | 24 +++++++++++++++++++++++- src/tests.ts | 10 +++++++--- src/util/misc.ts | 2 ++ 3 files changed, 32 insertions(+), 4 deletions(-) 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 } -- 2.49.1 From b3bb310df3b030bd68e7f8cf547483fe9eeff3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 12 May 2024 22:28:01 +0200 Subject: [PATCH 3/8] abstract --- src/TraitBuilder.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/TraitBuilder.ts b/src/TraitBuilder.ts index 2f129f8..74c7ff8 100644 --- a/src/TraitBuilder.ts +++ b/src/TraitBuilder.ts @@ -24,13 +24,13 @@ export class TraitBuilder< ) {} - abstract( - _: (Super: AbstractConstructor) => AbstractConstructor + abstract & StaticAbstract>( + _: (Super: AbstractConstructor & StaticAbstract) => A ) { return new TraitBuilder( this.traitSuperExpression, - {} as Simplify, - this.traitStaticAbstract, + {} as Simplify>, + {} as Simplify>, this.traitApply, ) } @@ -46,17 +46,6 @@ export class TraitBuilder< ) } - staticAbstract( - _: (Super: AbstractConstructor) => AbstractConstructor - ) { - return new TraitBuilder( - this.traitSuperExpression, - this.traitAbstract, - {} as Simplify, - this.traitApply, - ) - } - staticAbstractType( _: (Super: StaticAbstract) => typeof type ) { -- 2.49.1 From 57cab6a29ad4b43d985eafa8069f4cbd178aea70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 12 May 2024 23:03:56 +0200 Subject: [PATCH 4/8] Fix --- src/util/misc.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/misc.ts b/src/util/misc.ts index 85b4f9b..c83e71c 100644 --- a/src/util/misc.ts +++ b/src/util/misc.ts @@ -12,8 +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 } -- 2.49.1 From 0be0d5709def0b850002002051be06f13b2febbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 12 May 2024 23:26:16 +0200 Subject: [PATCH 5/8] Fix --- src/TraitBuilder.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TraitBuilder.ts b/src/TraitBuilder.ts index 74c7ff8..29a8cbc 100644 --- a/src/TraitBuilder.ts +++ b/src/TraitBuilder.ts @@ -174,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<{}>, ) -- 2.49.1 From 09613104533c0be7e7abe80f7d5d8b904e647c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 12 May 2024 23:44:37 +0200 Subject: [PATCH 6/8] Fix --- src/TraitExpression.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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< -- 2.49.1 From 8894ee90144ed6312877a5a23c862d3e091d0606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 13 May 2024 01:12:02 +0200 Subject: [PATCH 7/8] Fix --- src/effect/EffectSchemaTraitExpression.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) 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, -- 2.49.1 From d30c09b72143f58a7b285e2830859d90a9663e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 13 May 2024 01:14:01 +0200 Subject: [PATCH 8/8] Version bump --- bun.lockb | Bin 160474 -> 160474 bytes package.json | 10 +++++----- src/lib.ts | 2 +- 3 files changed, 6 insertions(+), 6 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