Skip to content

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

@kevinbeal

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

added this to the TypeScript 2.7.2 milestone on Feb 3, 2018
Conaclos

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]>'.

@kevinbeal
Your playground link is wrong (you need to hit "share" before copying the link).

kevinbeal

kevinbeal commented on Mar 5, 2018

@kevinbeal
Author

@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?

Conaclos

Conaclos commented on Mar 5, 2018

@Conaclos

@kevinbeal
Sorry, I expected the same code than the one posted here...

sandersn

sandersn commented on Mar 14, 2018

@sandersn
Member

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

added a commit that references this issue on Mar 15, 2018
5dfac15

104 remaining items

Loading
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

      Participants

      @alfaproject@chirdeeptomar@mdekrey@sandersn@shaunxu

      Issue actions

        Excessive Stack Depth from DeepPartial/RecursivePartial in 2.7.x · Issue #21592 · microsoft/TypeScript