Repository navigation
Excessive stack depth comparing types with TS 3.2 #29112
Description
Activity
- addedBugA bug in TypeScriptA bug in TypeScriptDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped types
on Dec 20, 2018 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>'.Reacted by aleitamar, hiradimir, Matthew Holloway, Steven Masala and Theophile Morinjohannesschobel commented
on Jan 20, 2019 More actionsI 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 :(
Reacted by Luciano SantanaReacted by Matthew Holloway and Haiyue MaSame issue here with TypeORM. :(
error TS2321: Excessive stack depth comparing types 'any' and 'FindConditions'.
Reacted by Jerome S., Sumanth Chinthagunta, Benjamin Houdu, Bart Van Remortele, Eduardo Leal, Mophy Xiong, Luis Eduardo Brito, Vladyslav, naisk133, Angelos Pikoulas and 21 moreReacted by Anton Ivanov, haiderali and Alijohannesschobel commented
on Feb 20, 2019 More actionsI think, the TypeORM related issue is the most common threat, why people end up in this issue here, haha ;)
Reacted by Anton IvanovReacted by Alexey Gerasimov and Anton IvanovThis issue is a deal breaker :-(
Reacted by Angelos PikoulasCan you guys please check it in the
0.2.15-rc.1? (npm i typeorm@0.2.15-rc.1)Reacted by Angelos PikoulasEDIT: it works with
npm i typescript@3.1.6
Unfortunately Umed Khudoiberdiev (@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
$ tsccompilation.Reacted by Luciano Santana, Luis Eduardo Brito and Thilo IlgThe only way I could reproduce this issue is when I did
gulp package(that does typescript compilation inside using gulp-typescript), usingtscis 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. Angelos Pikoulas (@anodynos) can you please provide some small reproduction where me (and maybe typescript team) can test this issue?FYI update: I hope I get this tested during Easter with latest TypeScript & ts-node and create a small reproduction repo :-)
lucianosantana commented
on Apr 24, 2019 More actionsI confirm it works with
typescript@3.1.6. I'm using that as a temporary workaround, since we were ontypescript@3.3.4000before. I've also tested with the latest version3.4.3and it's still broken.For all the tests I was using
typeorm@0.2.16Reacted by Roman, Luis Eduardo Brito, Arthur Conrado de Lima and Thilo IlgReacted by Arthur Conrado de LimaReacted by Arthur Conrado de LimaReacted by Arthur Conrado de LimaJust 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
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>;Reacted by Ihor Levchenko, Public Profile and Alberto Fernandez10 remaining items
- added a commit that references this issue
on Sep 1, 2019 misterjohannesson commented
on Sep 2, 2019 More actionsChiming in with the same error for new version of typeorm.
Node: v12.6.0
typeorm: v0.2.18
typescript: v3.6.2Downgrading typescript v.3.5.3
And then using @babel/plugin-proposal-decorators for my needed 3.6 feature has worked for now.Reacted by John Danek, Chris Kitch, Léo Pradel, Paróczi Gergő, Nick Paterno, Fredrik Hall, Eingress Ltd, Mitch Downey, Pascal Sthamer, Lars Baumeister and 3 moreReacted by Eingress LtdSame issue here, wondering what is the meaning of such an issue...
Reacted by Oleg, Plastikfan and Ayub Begimkulovsame issue here with
"typescript": "^4.2.3",node v10.16.0here error appears on
matchexport 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; }
Reacted by Rob Hilgefort, Jan Baykara and Olavo Rocha NetoFacing the same issue
Excessive stack depth comparing typesI am also facing this issue with Prisma when comparing two arrays with the types such as
Prisma.<NameOfTheEntity>CreateInput[].Reacted by Jack Burch and Attila TóthSame with a custom type I wrote coming from Nuxt type
export type FormNitroResponseType<R extends NitroFetchRequest, Y extends AvailableRouterMethod<R>> = Awaited<ReturnType<typeof $fetch<unknown, R, { method: Y } & NitroFetchOptions<R, Y>>>>;And appearing randomly. It's not always displayed as an error:
error TS2321: Excessive stack depth comparing typesWould be great to have a
--max-depth [number]parameter for compilation no?Btw I'm running
Version 5.8.3RyanCavanaugh commented
on Sep 1, 2026 MemberMore actionsThis was fixed by #33144 and is included in TypeScript 3.7. The recursive
PartialDeepcomparison covered by that change reports TS2321 undertsc --strictin 3.6.2, while it compiles in 3.7.2 and in the current 7.1.0-dev.20260901.1 nightly.- addedFixedA PR has been merged for this issueA PR has been merged for this issueNeeds Human ReviewThis issue has a backlog check awaiting maintainer review.This issue has a backlog check awaiting maintainer review.
on Sep 1, 2026 - removedNeeds Human ReviewThis issue has a backlog check awaiting maintainer review.This issue has a backlog check awaiting maintainer review.
on Sep 23, 2026

TypeScript Version: 3.2.2
Search Terms:
error TS2321: Excessive stack depth comparing types
lodash
Code
{ "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