From d9213e0083b72b4363e537a6627af1919b744d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 19 Feb 2024 22:41:20 +0100 Subject: [PATCH] TraitExpression fix --- src/TraitExpression.ts | 18 ++++++++++-------- src/tests.ts | 20 +++++++++++++++----- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/TraitExpression.ts b/src/TraitExpression.ts index 179839a..ade1782 100644 --- a/src/TraitExpression.ts +++ b/src/TraitExpression.ts @@ -15,11 +15,12 @@ export class TraitExpression< get extends(): ( AbstractClass< + InstanceType & // Keep the instance of the superclass outside of any kind of type manipulation + // as it can accidentely remove abstract properties Simplify< - Extend<[ - InstanceType, - ...TraitTuple.MapImplInstance, - ]> + Extend< + TraitTuple.MapImplInstance + > >, ConstructorParameters @@ -140,11 +141,12 @@ export type TraitExpressionConcreteClass< export type TraitExpressionInstance< Exp extends TraitExpression[]> > = ( + InstanceType> & // Keep the instance of the superclass outside of any kind of type manipulation + // as it can accidentely remove abstract properties Simplify< - Extend<[ - InstanceType>, - ...TraitTuple.MapInstance>, - ]> + Extend< + TraitTuple.MapInstance> + > > ) diff --git a/src/tests.ts b/src/tests.ts index b7ada34..3725da4 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -1,4 +1,4 @@ -import { Simplify } from "type-fest" +import { AbstractClass, Simplify } from "type-fest" import { TraitClass } from "./Trait" import { trait } from "./TraitBuilder" import { Implements, ImplementsStatic, TraitExpressionClass } from "./TraitExpression" @@ -85,7 +85,17 @@ class User extends exp.extends implements Implements { console.log(new User()) -type T = NonExtendableKeys<[ - { prout: "gneugneu" }, - { prout: string }, -]> +abstract class Test { + abstract prout: string +} + +const MappedTest = Test as AbstractClass + +class ConcreteTest extends MappedTest { + +} + +// type T = NonExtendableKeys<[ +// { prout: "gneugneu" }, +// { prout: string }, +// ]>