Repository navigation
Excessive Stack Depth from DeepPartial/RecursivePartial in 2.7.x #21592
Description
Activity
I got the same code with the next code:
type SafeAny <T> = { [k in keyof T]?: SafeAny<T[k]> } | boolean | number | string | symbol | null | undefined type DataValidator <T> = { [k in keyof T]?: (v: SafeAny<T[k]>) => v is T[k] }
The following error is reported:
error TS2321: Excessive stack depth comparing types 'T[k]' and 'SafeAny<T[k]>'.Kevin Beal (@kevinbeal)
Your playground link is wrong (you need to hit "share" before copying the link).Victorien Elvinger (@Conaclos) In what sense exactly is the link wrong? I did hit "share". It wouldn't be a really long URL with url encoded typescript in the URL if I hadn't. Are you not seeing the issue when you click the link?
Reacted by Victorien ElvingerKevin Beal (@kevinbeal)
Sorry, I expected the same code than the one posted here...sandersn commented
on Mar 14, 2018 MemberMore actionsFrom bisecting, the bad commit is part of #19564.
- added a commit that references this issue
on Mar 15, 2018 - addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Mar 19, 2018 69 remaining items
I bet a $ that we will see a message:
sandersn (or whoever) modified the milestones: TypeScript 3.5.0, TypeScript 3.6.0some day. 😿I won but disappointed. 😭
Now my questions is: Will it be moved to 3.7.0 😿 ? Should I bet 10$ ?
Reacted by Johannes Schobel, Haiyue Ma and wyqydsyq- added a commit that references this issue
on 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
- added a commit that references this issue
on Aug 29, 2019 lukejagodzinski commented
on Sep 3, 2019 More actionsIs it a bug in TypeScript compiler or just libraries' code is faulty? Maybe TS team should come up with some guidance how to write code to avoid this bug if it's not an issue with tsc itself. It's really frustrating that it didn't get fixed yet
- added 2 commits that reference this issue
on Sep 3, 2019 João Dias (@alfaproject) you have a different issue. Notice that the two types are the same in your case. This is a known bug (#33132) with a fix at #33144. We'll ship it in 3.6.3 in the next week or so.
Reacted by João DiasI hate this bug. The only thing is work agains it is
// @ts-ignoreFixed in 3.7
- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
Search Terms:
"excessive depth"
"generic partial"
Code
Expected behavior:
Comparing a generic with a partial of that generic working without errors.
Actual behavior:
Getting "Excessive stack depth comparing types 'T' and 'RecursivePartial'." since upgrading to 2.7.x. (Also errors in 2.8.x). Working in 2.6.1.
Playground Link:
https://www.typescriptlang.org/play/index.html#src=class%20Greeter%20%7B%0D%0A%20%20%20%20greeting%3A%20RecursivePartial%3Cstring%3E%3B%0D%0A%20%20%20%20constructor(message%3A%20string)%20%7B%0D%0A%20%20%20%20%20%20%20%20this.greeting%20%3D%20message%3B%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20greet()%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20%22Hello%2C%20%22%20%2B%20this.greeting%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Alet%20greeter%20%3D%20new%20Greeter(%22world%22)%3B%0D%0A%0D%0Alet%20button%20%3D%20document.createElement('button')%3B%0D%0Abutton.textContent%20%3D%20%22Say%20Hello%22%3B%0D%0Abutton.onclick%20%3D%20function()%20%7B%0D%0A%20%20%20%20alert(greeter.greet())%3B%0D%0A%7D%0D%0A%0D%0Adocument.body.appendChild(button)%3B%0D%0A%0D%0Aconst%20fn%20%3D%20%3CT%3E(arg%3A%20T)%20%3D%3E%20%7B%0D%0A%20%20%20%20((arg2%3A%20RecursivePartial%3CT%3E)%20%3D%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%0D%0A%20%20%20%20%7D)(arg)%3B%0D%0A%7D%3B%0D%0A%0D%0Atype%20RecursivePartial%3CT%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BP%20in%20keyof%20T%5D%3F%3A%20RecursivePartial%3CT%5BP%5D%3E%3B%0D%0A%7D%3B
Related Issues:
None?