Skip to content

Crash: RangeError: Maximum call stack size exceeded in addTypesToUnion when using incomplete keyof type annotation on object destructuring #62993

@na7ure-a

Description

@na7ure-a

🔎 Search Terms

addTypesToUnion stack overflow

getUnionTypeWorker crash

keyof missing type crash

Internal Compiler Error destructuring

🕗 Version & Regression Information

v5.7.3 / v5.8.3 / v5.9.3 / Nightly: Crashes(This crash only occurs when the --strict flag is enabled.)

⏯ Playground Link

https://www.typescriptlang.org/zh/play/?target=7&ts=6.0.0-dev.20260115#code/MYewdgzgLgBA3jYAaGATFBTFAzFBzGAXwC4YBrDATxGxhgF54AoOugOg7hdZ47a56DWfAULF1gpAAxJu4uoVnzWqaXMGL1PDGp6ae2JoQDcQA

💻 Code

const { c, d, e, f, g }: keyof  = {
    ...{
        ...{
            ...{
                c: 0,
            },
            d: 0
        },
        e: 0
    },
    f
};

🙁 Actual behavior

 .\ts-versions\nightly\node_modules\.bin\tsc.cmd --strict  .\mutated\destructuringSpread_mutated_batch15.ts
D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:123166
      throw e;
      ^

RangeError: Maximum call stack size exceeded
    at addTypesToUnion (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:61209:27)                                                                                                 
    at getUnionTypeWorker (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:61385:22)                                                                                              
    at getUnionType (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:61381:12)                                                                                                    
    at mapType (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:69885:37)                                                                                                         
    at getApparentTypeOfContextualType (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:73263:28)                                                                                 
    at checkObjectLiteral (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:73978:28)                                                                                              
    at checkExpressionWorker (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:80883:16)                                                                                           
    at checkExpression (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:80794:32)                                                                                                 
    at checkObjectLiteral (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:74062:37)                                                                                              
    at checkExpressionWorker (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:80883:16)                                                                                           

Node.js v22.19.0

🙂 Expected behavior

The compiler should report a syntax error and not crash.

Additional information about the issue

No response

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions