Excessive stack depth comparing types with TS 3.2 #29112
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped typesFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped typesFixedA PR has been merged for this issueA PR has been merged for this issue
Activity
vitaliusvs commentedon Jan 19, 2019
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 commentedon Jan 20, 2019
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 commentedon Feb 20, 2019
Same issue here with TypeORM. :(
error TS2321: Excessive stack depth comparing types 'any' and 'FindConditions'.
johannesschobel commentedon Feb 20, 2019
I think, the TypeORM related issue is the most common threat, why people end up in this issue here, haha ;)
vitia commentedon Mar 9, 2019
This issue is a deal breaker :-(
pleerock commentedon Mar 10, 2019
Can you guys please check it in the
0.2.15-rc.1? (npm i typeorm@0.2.15-rc.1)anodynos commentedon Mar 10, 2019
EDIT: it works with
npm i typescript@3.1.6Unfortunately Umed Khudoiberdiev (@pleerock) I get the same with 0.2.15-rc.1 (TS 3.3.3333, ts-node: 8.0.3):
Weirdly enough it works fine with just a
$ tsccompilation.pleerock commentedon Mar 11, 2019
The 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?anodynos commentedon Apr 18, 2019
FYI update: I hope I get this tested during Easter with latest TypeScript & ts-node and create a small reproduction repo :-)
lucianosantana commentedon Apr 24, 2019
I 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.16alfaproject commentedon 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:
https://github.com/crcn/sift.js/blob/ef8c5ca2e4b4277cf79085dd4168dbbe58ea4869/index.d.ts
P.S.: Maybe related? #21592
achansonjr commentedon Aug 28, 2019
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.
10 remaining items
downgrade ts to 3.5.3, microsoft/TypeScript#29112
fix: microsoft/TypeScript#29112
downgrade typescript until issue is fixed
misterjohannesson commentedon Sep 2, 2019
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 commentedon Sep 10, 2019
Same issue here, wondering what is the meaning of such an issue...
hallya commentedon Mar 20, 2021
same issue here with
"typescript": "^4.2.3",node v10.16.0here error appears on
matchEDIT :
fixed with
Array.from:tylim88 commentedon Jun 30, 2022
same issue here, v4.7.4

playground
no error if i change the type to
V extends unknown[]AaravShah042 commentedon Jul 8, 2022
Facing the same issue
Excessive stack depth comparing typesLyokolux commentedon Aug 25, 2022
I am also facing this issue with Prisma when comparing two arrays with the types such as
Prisma.<NameOfTheEntity>CreateInput[].oom- commentedon May 8, 2025
Same 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 commentedon Sep 1, 2026
This 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.