Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript 2.7.1 update cause repository.save(entity) error #1544

Closed
rafaelbatistamarcilio opened this issue Feb 2, 2018 · 24 comments
Closed

Comments

@rafaelbatistamarcilio
Copy link

Issue type:

[ ] question
[x ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x ] postgres
[ ] sqlite
[ ] sqljs
[ ] websql

TypeORM version:

[ x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

When i update my typescript version to 2.7.1 my application's build broken with the follow error:

PS C:\dsv\nest-api> npm run start:prod

nest-typescript-starter@1.0.0 prestart:prod C:\dsv\nest-api
tsc

src/modules/common/services/base-data.service.ts(46,65): error TS2321: Excessive stack depth comparing types 'T' and 'DeepPartial'.
src/modules/common/services/base-data.service.ts(67,65): error TS2345: Argument of type 'T' is not assignable to parameter of type 'DeepPartial'.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! nest-typescript-starter@1.0.0 prestart:prod: tsc
npm ERR! Exit status 2

The service code is the follow:

export abstract class BaseDataService<T extends BaseModel> implements ICrudService<T>{

    constructor() {

    }
   
    ... other crud methods   

    public abstract getRepository(): Repository<T>;
    
    public async save(entity: T): Promise<T> {
        try {
            const response: T = await this.getRepository().save(entity);
            return response;
        } catch (error) {
            throw new BadGatewayException('ERROR.BASEDATASERVICE.SAVE');
        }
   }

}

Someone know why this is happening?

Thanks!

@daniel-lang
Copy link
Contributor

There is an issue open for that (microsoft/TypeScript#21671). It seems like a regression issue on their part. Let's see what they have to say.

@pleerock
Copy link
Member

@daniel-lang how to reproduce this?

$ ./node_modules/.bin/tsc
$ ./node_modules/.bin/tsc -v
Version 2.7.1

I don't have such error checking on typescript-example with typeorm 0.1.12 installed.

@daniel-lang
Copy link
Contributor

I'm unable to reproduce it now, but when I wrote the comment I was. That's very strange.

@pleerock
Copy link
Member

@rafaelbatistamarcilio @adrianhara can you provide more information?

@xavism
Copy link

xavism commented Mar 2, 2018

I'm stack too in this problem.. I'm using ts 2.7.2.

@pleerock
Copy link
Member

pleerock commented Mar 2, 2018

anyone can tell how to reproduce this issue?

@xavism
Copy link

xavism commented Mar 2, 2018

I can give you my repo if you want, there you have the version of each npm package.
I'm using NestJS with typeORM with a MySQL DB.

just:
npm i
npm start

You should change the typeormconfig to change the db

@pleerock
Copy link
Member

pleerock commented Mar 2, 2018

yes it would be great

@xavism
Copy link

xavism commented Mar 2, 2018

this is my repo:
Thx to check it out.

https://github.com/xavism/nestjs-crud

@pleerock
Copy link
Member

pleerock commented Mar 2, 2018

@xavism thanks for the repo, but I expected something simple with a few lines of code, since example is complex Im not sure where is a problem.

Lets wait until microsoft/TypeScript#21671 is resolved by typescript team.

@xavism
Copy link

xavism commented Mar 2, 2018

Sorry I thought would be easier to reproduce it.

Here I add a simple example

export class BaseService<T extends BaseEntity> implements IBaseService<T>{
	constructor(
    private readonly genericRepository: Repository<T>) {
		console.log('Im the ORM Service');
	}

  create(entity: T): Promise<number>{
		return new Promise<number> ((resolve, reject) => {
			this.genericRepository.save(entity)
			.then(created=> resolve(created.id))
			.catch(err => reject(err))
			})
  }
}

@xavism
Copy link

xavism commented Mar 3, 2018

The problem is generated in the save method, where you pass a parameter of type T

@aymehri
Copy link

aymehri commented Mar 19, 2018

I have the same error, any updates?

@daniel-lang
Copy link
Contributor

@aymehri microsoft/TypeScript#21671 in favor of microsoft/TypeScript#21592 in which the Typescript Team acknowledged that it's a bug. The current target for a fix is TypeScript 2.8.1

@aymehri
Copy link

aymehri commented Mar 20, 2018

Thank you @daniel-lang , we just wait then. :)

@xavism
Copy link

xavism commented Mar 22, 2018

@aymehri To use it before the fix in TS 2.8.1, you just have to pass the entity as any.

@pleerock
Copy link
Member

I'll close it, let's track a typescript issue instead.

@pleerock
Copy link
Member

Can you guys please check it in the 0.2.15-rc.1 ? (npm i typeorm@0.2.15-rc.1)

@ancyrweb
Copy link

Can confirm this work !

@pleerock
Copy link
Member

Great! Would be great if everyone else confirm it

@EduardsE
Copy link

EduardsE commented Apr 4, 2019

Downgrading to 0.2.15-rc.1 did not fix the issue for me.

@pisix
Copy link

pisix commented Apr 4, 2019

me too

@EduardsE
Copy link

EduardsE commented Apr 5, 2019

Although what did fix the issue was downgrading typescript to version 3.3.4000

@lucianosantana
Copy link

Not for me, I was in 3.3.400. Downgrading to 3.1.6 did work, though. See : microsoft/TypeScript#29112 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants