nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.04k stars 533 forks source link

Update to typeorm 0.2.42 gives compilation error #768

Open in-live-md opened 2 years ago

in-live-md commented 2 years ago

Saw this when upgrading typeorm to latest (0.2.43). Issue arises in 02.42. Fix was to revert to 0.2.41

node_modules/@nestjsx/crud-typeorm/lib/typeorm-crud.service.d.ts:30:5 - error TS2416: Property 'createOne' in type 'TypeOrmCrudService<T>' is not assignable to the same property in base type 'CrudService<T>'.
  Type '(req: CrudRequest, dto: DeepPartial<T>) => Promise<T>' is not assignable to type '(req: CrudRequest, dto: T) => Promise<T>'.
    Types of parameters 'dto' and 'dto' are incompatible.
      Type 'T' is not assignable to type 'DeepPartial<T>'.

30     createOne(req: CrudRequest, dto: DeepPartial<T>): Promise<T>;
       ~~~~~~~~~

node_modules/@nestjsx/crud-typeorm/lib/typeorm-crud.service.d.ts:32:5 - error TS2416: Property 'updateOne' in type 'TypeOrmCrudService<T>' is not assignable to the same property in base type 'CrudService<T>'.
  Type '(req: CrudRequest, dto: DeepPartial<T>) => Promise<T>' is not assignable to type '(req: CrudRequest, dto: T) => Promise<T>'.
    Types of parameters 'dto' and 'dto' are incompatible.
      Type 'T' is not assignable to type 'DeepPartial<T>'.

32     updateOne(req: CrudRequest, dto: DeepPartial<T>): Promise<T>;
       ~~~~~~~~~

node_modules/@nestjsx/crud-typeorm/lib/typeorm-crud.service.d.ts:33:5 - error TS2416: Property 'replaceOne' in type 'TypeOrmCrudService<T>' is not assignable to the same property in base type 'CrudService<T>'.
  Type '(req: CrudRequest, dto: DeepPartial<T>) => Promise<T>' is not assignable to type '(req: CrudRequest, dto: T) => Promise<T>'.
    Types of parameters 'dto' and 'dto' are incompatible.
      Type 'T' is not assignable to type 'DeepPartial<T>'.

33     replaceOne(req: CrudRequest, dto: DeepPartial<T>): Promise<T>;
       ~~~~~~~~~~

[9:40:39 AM] Found 3 errors. Watching for file changes.

git diffing typeorm 0.2.42 with 0.2.41 found the following which may be the cause

index 17223f43..0b8b0f70 100644
--- a/src/entity-manager/EntityManager.ts
+++ b/src/entity-manager/EntityManager.ts
@@ -163,17 +163,17 @@ export class EntityManager {
     }

     createQueryBuilder<Entity>(entityClass?: EntityTarget<Entity>|QueryRunner, alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity> {
         if (alias) {
@@ -247,7 +247,7 @@ export class EntityManager {
             return metadata.create(this.queryRunner);

         if (Array.isArray(plainObjectOrObjects))
-            return plainObjectOrObjects.map(plainEntityLike => this.create(entityClass as any, plainEntityLike));
+            return (plainObjectOrObjects as DeepPartial<Entity>[]).map(plainEntityLike => this.create(entityClass, plainEntityLike));
kevinmuoz commented 2 years ago

@in-live-md What is your version of Typescript? I've tried different versions and it still doesn't work...I hope they fix it soon

in-live-md commented 2 years ago

4.5.5 - look at the change that casts plainObjectorObjects to DeepPartial I believe that is what introduced the issue

TomerElya commented 2 years ago

Having the same issue I downgraded to 0.2.41 like you said and it fixed my problem

bence-sebok commented 2 years ago

Had the same issue, downgrading to typeorm 0.2.41 fixed the problem for me, too.

H4ad commented 2 years ago

The problem is with the TypeOrmCrudService and how they are typed.

I create a fix in rewiko version of nestjsx/crud.

in-live-md commented 2 years ago

The problem is with the TypeOrmCrudService and how they are typed.

I create a fix in rewiko version of nestjsx/crud.

@H4ad So no one is maintaining nestjsx/crud repo i take it? And rewiko is where most are going to stay current with original nestjsx/crud?

H4ad commented 2 years ago

@in-live-md We are still waiting for zMotivat0r to give deployment access to rewiko because it has set out to be a new maintainer. Until this is done, rewiko has forked it to release some fixes and updates to the library.

You can see more in #710.

bence-sebok commented 2 years ago

I see, thanks for your explanations. I will check rewiko's fork and I suppose we can use that in our project.

duongleh commented 2 years ago

@michaelyali can you take a look at this? This bug blocks us from using the newer version of typeorm with your package.

rewiko commented 2 years ago

Sorry for the delay @H4ad, new version 5.1.2 includes this PR https://www.npmjs.com/package/@rewiko/crud

Thanks for the PR :)