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 with TS 3.2 #29112

Open
GabrielCastro opened this issue Dec 20, 2018 · 25 comments
Open

Excessive stack depth comparing types with TS 3.2 #29112

GabrielCastro opened this issue Dec 20, 2018 · 25 comments
Labels
Bug A bug in TypeScript Domain: Mapped Types The issue relates to mapped types
Milestone

Comments

@GabrielCastro
Copy link

TypeScript Version: 3.2.2

Search Terms:
error TS2321: Excessive stack depth comparing types
lodash

Code

import { PartialDeep, pick } from 'lodash';

type MapFunc<T> = (data: PartialDeep<T>) => PartialDeep<T>;

function testFunc<T>(): MapFunc<T> {
  return data => pick<PartialDeep<T>>(data, []) as PartialDeep<T>;
}
{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "lib": ["es2018", "dom"],
    "strict": true,
    "noEmitOnError": true
  }
}

Expected behavior:
This code should compile with TS 3.2 as it will with TS 3.1

Actual behavior:
Compliation fails with the following error

error TS2321: Excessive stack depth comparing types 'PartialDeep<T>' and 'PartialDeep<PartialDeep<T>>'.


Found 2 errors. 
@weswigham weswigham added Bug A bug in TypeScript Domain: Mapped Types The issue relates to mapped types labels Dec 20, 2018
@vitaliusvs
Copy link

typescript@3.2.4

C:\dev\server\node_modules\ts-node\src\index.ts:261
return new TSError(diagnosticText, diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
error TS2321: Excessive stack depth comparing types 'any' and 'ListIterateeCustom<T, boolean>'.
error TS2321: Excessive stack depth comparing types 'any' and 'ObjectIterateeCustom<T[], boolean>'.

@johannesschobel
Copy link

I can confirm, that this issue still persists in TypeScript@3.2.4..
This thread, however, is a duplicate of #21592 .

This issue was introduced somehwere in 2.7.x - and has been moved from milestone to milestone to get fixed. Unfortunately, this has not been the case for now :(

@gabrielbiga
Copy link

Same issue here with TypeORM. :(

error TS2321: Excessive stack depth comparing types 'any' and 'FindConditions'.

@johannesschobel
Copy link

I think, the TypeORM related issue is the most common threat, why people end up in this issue here, haha ;)

@vitia
Copy link

vitia commented Mar 9, 2019

This issue is a deal breaker :-(

@pleerock
Copy link

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

@anodynos
Copy link

anodynos commented Mar 10, 2019

EDIT: it works with npm i typescript@3.1.6


Unfortunately @pleerock I get the same with 0.2.15-rc.1 (TS 3.3.3333, ts-node: 8.0.3):

╰─$ ts-node src/code/server.ts    
OR 
╰─$ node -r ts-node/register src/code/server.ts
                                                                                                                                              1 ↵
error: uncaughtException: ⨯ Unable to compile TypeScript:
error TS2321: Excessive stack depth comparing types 'any' and 'FindConditions<TEntity> | undefined'.
 date=Sun Mar 10 2019 20:30:52 GMT+0000 (Greenwich Mean Time), pid=5728, uid=1000, gid=1000, cwd=/mnt/projects/projects/pickpeak/api, execPath=/usr/local/bin/node, version=v11.8.0, argv=[/devtools/npm-global/bin/ts-node, /mnt/projects/projects/pickpeak/api/src/code/server.ts], rss=440221696, heapTotal=364154880, heapUsed=257885040, external=87005, loadavg=[1.3564453125, 1.87939453125, 0.99951171875], uptime=409, trace=[column=12, file=/devtools/npm-global/lib/node_modules/ts-node/src/index.ts, function=createTSError, line=226, method=null, native=false, column=40, file=/devtools/npm-global/lib/node_modules/ts-node/src/index.ts, function=getOutput, line=335, method=null, native=false, column=11, file=/devtools/npm-global/lib/node_modules/ts-node/src/index.ts, function=Object.compile, line=368, method=compile, native=false, column=43, file=/devtools/npm-global/lib/node_modules/ts-node/src/index.ts, function=Module.m._compile, line=414, method=_compile, native=false, column=10, file=internal/modules/cjs/loader.js, function=Module._extensions..js, line=747, method=.js, native=false, column=12, file=/devtools/npm-global/lib/node_modules/ts-node/src/index.ts, function=Object.require.extensions.(anonymous function) [as .ts], line=417, method=ts], native=false, column=32, file=internal/modules/cjs/loader.js, function=Module.load, line=628, method=load, native=false, column=12, file=internal/modules/cjs/loader.js, function=tryModuleLoad, line=568, method=null, native=false, column=3, file=internal/modules/cjs/loader.js, function=Module._load, line=560, method=_load, native=false, column=17, file=internal/modules/cjs/loader.js, function=Module.require, line=665, method=require, native=false], stack=[TSError: ⨯ Unable to compile TypeScript:, error TS2321: Excessive stack depth comparing types 'any' and 'FindConditions<TEntity> | undefined'., ,     at createTSError (/devtools/npm-global/lib/node_modules/ts-node/src/index.ts:226:12),     at getOutput (/devtools/npm-global/lib/node_modules/ts-node/src/index.ts:335:40),     at Object.compile (/devtools/npm-global/lib/node_modules/ts-node/src/index.ts:368:11),     at Module.m._compile (/devtools/npm-global/lib/node_modules/ts-node/src/index.ts:414:43),     at Module._extensions..js (internal/modules/cjs/loader.js:747:10),     at Object.require.extensions.(anonymous function) [as .ts] (/devtools/npm-global/lib/node_modules/ts-node/src/index.ts:417:12),     at Module.load (internal/modules/cjs/loader.js:628:32),     at tryModuleLoad (internal/modules/cjs/loader.js:568:12),     at Function.Module._load (internal/modules/cjs/loader.js:560:3),     at Module.require (internal/modules/cjs/loader.js:665:17)]

Weirdly enough it works fine with just a $ tsc compilation.

@pleerock
Copy link

The only way I could reproduce this issue is when I did gulp package (that does typescript compilation inside using gulp-typescript), using tsc is also fine to me. Then I changed some of the code (still valid typescript code, I just restructured something) and gulp compilation worked fine. I thought issue is fixed. @anodynos can you please provide some small reproduction where me (and maybe typescript team) can test this issue?

@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 14, 2019
@anodynos
Copy link

FYI update: I hope I get this tested during Easter with latest TypeScript & ts-node and create a small reproduction repo :-)

@lucianosantana
Copy link

I confirm it works with typescript@3.1.6. I'm using that as a temporary workaround, since we were on typescript@3.3.4000 before. I've also tested with the latest version 3.4.3 and it's still broken.

For all the tests I was using typeorm@0.2.16

@alfaproject
Copy link

alfaproject commented Aug 28, 2019

Just got hit by this in TS 3.6.2 which Renovate bot just attempted to update to and our pipeline failed. ):

It's not even our own code. It comes from one of the libraries that we use:

error TS2321: Excessive stack depth comparing types 'ElemMatch<?>' and 'ElemMatch<?>'.
error TS2321: Excessive stack depth comparing types 'InternalQuery<?>' and 'InternalQuery<?>'.
error TS2321: Excessive stack depth comparing types 'SiftQuery<?>' and 'SiftQuery<?>'.

https://github.com/crcn/sift.js/blob/ef8c5ca2e4b4277cf79085dd4168dbbe58ea4869/index.d.ts

P.S.: Maybe related? #21592

@achansonjr
Copy link

After upgrading to TS 3.6.2 got this error from a dependency library Typeorm as well. Reverting back to TS@3.5.3 and the issue went away.

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> | undefined, maybeOptions?: FindOneOptions<Entity> | undefined) => Promise<...>' and '{ (id?: string | number | Date | ObjectID | undefined, options?: FindOneOptions<Entity> | undefined): Promise<Entity | undefined>; (options?: FindOneOptions<Entity> | undefined): Promise<...>; (conditions?: FindConditions<...> | undefined, options?: FindOneOptions<...> | undefined): Promise<...>; }'.

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

@ghost
Copy link

ghost commented Aug 28, 2019

Downgrading to TS@3.5.3 resolved the issue for me as well.

@sidewaiise
Copy link

Im experiencing this in one of my projects. package.json had ^3.4.3 . Taking away the hat fixed the issue. Using it with loopback 4, so the error was:

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

@lilacdev
Copy link

I confirm that typescript@3.1.6 solves this issue for TypeORM users (through NestJS).

@guillaume-roy
Copy link

Like @michaelharrisonroth we've just downgraded to typescript@3.5.3 to solve the issue.

@olehcambel
Copy link

olehcambel commented Aug 29, 2019

Strange error. For me helped to change version of typescript.
f.e. project without node_modules and build.

  1. npm i (with typescript@3.5.3)
  2. npm run build it fails with related error
  3. npm i -D typescript@3.5.2
  4. npm run build it build with success

It works vice versa with no matter what version is it(except 3.6.2)

@perzanko
Copy link

Same issue here 😎

@IamFlowZ
Copy link

IamFlowZ commented Aug 29, 2019

Just had this issue occur for me while trying to build a typeorm project in AWS CodeBuild and locally in ubuntu 18.04:

Versions:
Node: v10.16.3 & v12.6.0
Typescript: 3.6.2
TypeORM: 0.2.16

Console output:
$ tsc -p .
error TS2321: Excessive stack depth comparing types 'FindConditions' and 'FindConditions'.

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

controller.ts:170:33 - error TS2589: Type instantiation is excessively deep and possibly infinite.

170 status: MoreThanOrEqual(1)
~~~~~~~~~~~~~~~~~~

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

12 export declare class MongoRepository extends Repository {
~~~~~~~~~~~~~~~

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

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

zoubingwu added a commit to zoubingwu/paperin that referenced this issue Aug 31, 2019
marcelovicentegc pushed a commit to marcelovicentegc/george that referenced this issue Aug 31, 2019
obedm503 added a commit to obedm503/nuffread that referenced this issue Sep 1, 2019
@misterjohannesson
Copy link

Chiming in with the same error for new version of typeorm.

Node: v12.6.0
typeorm: v0.2.18
typescript: v3.6.2

Downgrading typescript v.3.5.3
And then using @babel/plugin-proposal-decorators for my needed 3.6 feature has worked for now.

@jeromeSH26
Copy link

Same issue here, wondering what is the meaning of such an issue...

@hallya
Copy link

hallya commented Mar 20, 2021

same issue here with "typescript": "^4.2.3", node v10.16.0

here error appears on match

export function getCookie(key: string) {
  const matches = document.cookie.match(new RegExp(`(?:^|; )${key}=([^;]*)`));

  if (matches) {
    const [, match] = matches;
    const cookieValue = decodeURIComponent(match);
    return cookieValue;
  }
  return null;
}

EDIT :

fixed with Array.from :

export function getCookie(key: string) {
  const matches = document.cookie.match(new RegExp(`(?:^|; )${key}=([^;]*)`));

  if (matches) {
    const [, match] = Array.from(matches);
    const cookieValue = decodeURIComponent(match);
    return cookieValue;
  }
  return null;
}

@tylim88
Copy link

tylim88 commented Jun 30, 2022

same issue here, v4.7.4
image

playground

no error if i change the type to V extends unknown[]

@AaravShah042
Copy link

Facing the same issue
Excessive stack depth comparing types

@Lyokolux
Copy link

I am also facing this issue with Prisma when comparing two arraws with the types such as Prisma.<NameOfTheEntity>CreateInput[].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Mapped Types The issue relates to mapped types
Projects
None yet
Development

No branches or pull requests