Skip to content

Excessive Stack Depth from DeepPartial/RecursivePartial in 2.7.x #21592

Description

@kevinbeal

Search Terms:
"excessive depth"
"generic partial"

Code

const fn = <T>(arg: T) => {
    ((arg2: RecursivePartial<T>) => {
        // ...
    })(arg); // <-- here
};

type RecursivePartial<T> = {
    [P in keyof T]?: RecursivePartial<T[P]>;
};

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?

Activity

  1. Conaclos commented on Mar 3, 2018

    @Conaclos

    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).

  2. kevinbeal commented on Mar 5, 2018

    @kevinbeal
    Author

    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?

  3. Conaclos commented on Mar 5, 2018

    @Conaclos

    Kevin Beal (@kevinbeal)
    Sorry, I expected the same code than the one posted here...

  4. sandersn commented on Mar 14, 2018

    @sandersn
    Member

    From bisecting, the bad commit is part of #19564.

  5. added a commit that references this issue on Mar 15, 2018
    5dfac15
  6. modified the milestones: TypeScript 2.8.1, on Mar 19, 2018
  7. 69 remaining items

  8. Yaojian commented on Aug 15, 2019

    @Yaojian

    I bet a $ that we will see a message: sandersn (or whoever) modified the milestones: TypeScript 3.5.0, TypeScript 3.6.0 some day. 😿

    I won but disappointed. 😭

    Now my questions is: Will it be moved to 3.7.0 😿 ? Should I bet 10$ ?

  9. alfaproject commented on Aug 28, 2019

    @alfaproject

    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

  10. lukejagodzinski commented on Sep 3, 2019

    @lukejagodzinski

    Is 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

  11. sandersn commented on Sep 4, 2019

    @sandersn
    Member

    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.

  12. tomaswrobel commented on Mar 21, 2021

    @tomaswrobel

    I hate this bug. The only thing is work agains it is // @ts-ignore

  13. sandersn commented on Nov 5, 2021

    @sandersn
    Member

    Fixed in 3.7

  14. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions