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

Excessive stack depth comparing types 'FindConditions<?>' and 'FindConditions<?>' (with solution) #4427

Closed
mophy opened this issue Jul 12, 2019 · 13 comments

Comments

@mophy
Copy link
Contributor

mophy commented Jul 12, 2019

Issue type:

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

Database system/driver:

[ ] cordova
[x] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:

Compile any code that will use the FindConditions type, and the error occurs:

error TS2321: Excessive stack depth comparing types 'FindConditions<?>' and 'FindConditions<?>'.

TypeScript versions which will trigger this error: 3.2.4, 3.5.3
TypeScript versions which will NOT trigger this error: <=3.1.6

According to this link, this can be fixed, just modify the FindConditions.d.ts file from

export declare type FindConditions<T> = {
    [P in keyof T]?: FindConditions<T[P]> | FindOperator<FindConditions<T[P]>>;
};

to

export declare type FindConditions<T> = {
    [P in keyof T]?: T[P] extends never ? FindConditions<T[P]> | FindOperator<FindConditions<T[P]>> : FindConditions<T[P]> | FindOperator<FindConditions<T[P]>>;
};

After this change, TypeScript 3.2.4 and 3.5.3 will not trigger that error, and TypeScript 3.1.6 works well too.

I can submit a PR if needed.

@mophy mophy changed the title Excessive stack depth comparing types 'FindConditions<?>' and 'FindConditions<?>' Excessive stack depth comparing types 'FindConditions<?>' and 'FindConditions<?>' (with solution) Jul 13, 2019
haggholm added a commit to haggholm/typeorm that referenced this issue Aug 28, 2019
@Aibokalv
Copy link

Aibokalv commented Aug 31, 2019

i fix this problem by run npm install typescript@3.5.2 --save -g

@jraoult
Copy link

jraoult commented Sep 2, 2019

@mophy thx for the suggestion. I'm not the repo maintainer but I think you should create a PR. It's an easy one to merge and hopefully, we can get someone to accept it quickly 😄

@hbjydev
Copy link

hbjydev commented Sep 2, 2019

I've got this issue with MongoRepository#findOne

@hbjydev
Copy link

hbjydev commented Sep 2, 2019

error TS2321: Excessive stack depth comparing types 'MongoRepository<Entity>' and 'Repository<Entity>'.

node_modules/typeorm/repository/MongoRepository.d.ts:12:22 - error TS2589: Type instantiation is excessively deep and possibly infinite.

12 export declare class MongoRepository<Entity extends ObjectLiteral> extends Repository<Entity> {
                        ~~~~~~~~~~~~~~~

node_modules/typeorm/repository/MongoRepository.d.ts:45:5 - error TS2321: Excessive stack depth comparing types '(optionsOrConditions?: string | number | Date | ObjectID | FindOneOptions<Entity> | Partial<Entity>, maybeOptions?: FindOneOptions<Entity>) => Promise<Entity>' and '{ (id?: string | number | Date | ObjectID, options?: FindOneOptions<Entity>): Promise<Entity>; (options?: FindOneOptions<Entity>): Promise<Entity>; (conditions?: FindConditions<Entity>, options?: FindOneOptions<...>): Promise<...>; }'.

45     findOne(optionsOrConditions?: string | number | Date | ObjectID | FindOneOptions<Entity> | Partial<Entity>, maybeOptions?: FindOneOptions<Entity>): Promise<Entity | undefined>;
       ~~~~~~~

@mophy
Copy link
Contributor Author

mophy commented Sep 2, 2019

@jraoult, PR is here: #4470

@mophy
Copy link
Contributor Author

mophy commented Sep 2, 2019

@haydennyyy, there's a workaround in PR #4470

@keawade
Copy link

keawade commented Sep 3, 2019

This is probably related to this issue in Typescript: microsoft/TypeScript#21592

@risa
Copy link
Contributor

risa commented Sep 6, 2019

It seems that a Typescript fix is coming, I can confirm that it works with the 3.7.0-insiders.20190902 version.
See here: microsoft/TypeScript#33144 (comment)

@Majidahmadi
Copy link

In compile by typescript 3.6.2 , this problem is encountered, but there is no problem in 3.4.5 version!

@Kononnable
Copy link
Contributor

Looks like issue was resolved some time ago.

@gbar
Copy link

gbar commented Jun 8, 2020

Hi guys,
this fix

export declare type FindConditions<T> = {
    [P in keyof T]?: T[P] extends never ? FindConditions<T[P]> | FindOperator<FindConditions<T[P]>> : FindConditions<T[P]> | FindOperator<FindConditions<T[P]>>;
};

is causing

No overload matches this call.
  Overload 1 of 3, '(id?: string | number | Date | ObjectID, options?: FindOneOptions<T>): Promise<T>', gave the following error.
    Argument of type '{ hash: string; }' is not assignable to parameter of type 'string | number | Date | ObjectID'.
      Object literal may only specify known properties, and 'hash' does not exist in type 'Date | ObjectID'.
  Overload 2 of 3, '(conditions?: FindConditions<T>, options?: FindOneOptions<T>): Promise<T>', gave the following error.
    Argument of type '{ property: type; }' is not assignable to parameter of type 'FindConditions<T>'.

Argument of type '{ sourceId: string; createdAt: FindOperator<Date>; }' is not assignable to parameter of type 'string | number | string[] | Date | number[] | Date[] | ObjectID | ObjectID[] | FindConditions<T>'.
  Types of property 'sourceId' are incompatible.
    Type 'string' is not assignable to type 'T["sourceId"] extends never ? FindConditions<T["sourceId"]> | FindOperator<FindConditions<T["sourceId"]>> : FindConditions<T["sourceId"]> | FindOperator<...>'.

when I'm using

export class EntityService<T extends EntityClass, Source extends BaseEntity> {
  protected constructor(
    protected readonly tokenRepository: Repository<T>,
    protected readonly expirationTime: number = 3600,
  ) {}
....
}

this doesn't help

export class EntityService<Source extends BaseEntity, T extends EntityClass = EntityClass> {

moreover, it doesn't work with that either

export type DeepPartial<T> = {
    [P in keyof T]?:
        T[P] extends Array<infer U> ? Array<DeepPartial<U>> :
        T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> :
        DeepPartial<T[P]>
};

in version 0.2.18 there is no issue with that code

@greenreign
Copy link

@gbar did you ever figure out a solution? I'm running into the same issue in 0.2.36

@eliaspn
Copy link

eliaspn commented Oct 5, 2022

in my case going from 0.2.37 -> 0.2.45 fixed the issue

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