Char2sGu / mikro-orm-soft-delete

Generic soft delete solution for MikroORM.
Apache License 2.0
32 stars 10 forks source link

is this support Inheritance? #8

Closed jays1204 closed 9 months ago

jays1204 commented 9 months ago

I think this is not support inheritance. is it right?

 @SoftDeletable(() => SoftDeletableBaseEntity, "deletedAt", () => new Date())
 export abstract class SoftDeletableBaseEntity extends BaseEntity {
   @Property({ nullable: true })
   deletedAt?: Date;
 }

 @Entity()
 class DeleteEntity extends SoftDeletableBaseEntity {
     @Property()
     name: string;
 }

Above code, We can see errors like this.

error TS1238: Unable to resolve signature of class decorator when called as an expression.
      Argument of type 'typeof SoftDeletableBaseEntity' is not assignable to parameter of type 'Type<SoftDeletableBaseEntity>'.

    48 @SoftDeletable(() => SoftDeletableBaseEntity, "deletedAt", () => new Date())
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error TS2322: Type 'typeof SoftDeletableBaseEntity' is not assignable to type 'Type<SoftDeletableBaseEntity>'.
      Cannot assign an abstract constructor type to a non-abstract constructor type.

    48 @SoftDeletable(() => SoftDeletableBaseEntity, "deletedAt", () => new Date())

https://github.com/TheNightmareX/mikro-orm-soft-delete/blob/main/src/decorator.ts#L12 this line use 'new' keyword of T. But If T is abstract class, then it can not use 'new' keyword.

So I think @SoftDeletable decorator can not used on abstract class. 'm assuming you don't use this decorator for abstract classes?

Char2sGu commented 9 months ago

Hey @jays1204 thanks for reminding. Abstract signatures were not considered. This will be fixed in the next patch release.

Char2sGu commented 9 months ago

@jays1204 fixed in 1.0.0-alpha.1