Skip to content

"RangeError: Maximum call stack size exceeded" error after upgrading from 5.6.3 to 5.7.2 #60564

Closed

Description

@epmatsw

🔎 Search Terms

"Maximum call stack size exceeded", "getContextualTypeForObjectLiteralElement", "checkNonNullExpression"

🕗 Version & Regression Information

This changed between versions 5.7.0-dev.20240930 and 5.7.0-dev.20241001

I ran into this bug upgrading from 5.6.3 to 5.7.2 and bisected to that particular release.

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20241122#code/KYDwDg9gTgLgBAYwgOwM7xgCwJbIOZwC8cA3gFACQAJhNjABQCUplFUwMArlMixfwG0s2VADoAhgF0AXHABEcgDSsAvgG5KK5eqA

💻 Code

I don't have a narrowed code example, it just crashes when running tsc --noEmit on our whole project.

🙁 Actual behavior

RangeError: Maximum call stack size exceeded
    at getContextualTypeForObjectLiteralElement (/Users/will/.nvm/versions/node/v22.11.0/lib/node_modules/typescript/lib/_tsc.js:71872:52)
    at getContextualTypeForObjectLiteralMethod (/Users/will/.nvm/versions/node/v22.11.0/lib/node_modules/typescript/lib/_tsc.js:71870:12)
    at getApparentTypeOfContextualType (/Users/will/.nvm/versions/node/v22.11.0/lib/node_modules/typescript/lib/_tsc.js:72086:58)
    at getContextualSignature (/Users/will/.nvm/versions/node/v22.11.0/lib/node_modules/typescript/lib/_tsc.js:72485:18)
    at getContextualThisParameterType (/Users/will/.nvm/versions/node/v22.11.0/lib/node_modules/typescript/lib/_tsc.js:71308:35)
    at tryGetThisTypeAt (/Users/will/.nvm/versions/node/v22.11.0/lib/node_modules/typescript/lib/_tsc.js:71103:33)
    at checkThisExpression (/Users/will/.nvm/versions/node/v22.11.0/lib/node_modules/typescript/lib/_tsc.js:71061:18)
    at checkExpressionWorker (/Users/will/.nvm/versions/node/v22.11.0/lib/node_modules/typescript/lib/_tsc.js:79624:16)
    at checkExpression (/Users/will/.nvm/versions/node/v22.11.0/lib/node_modules/typescript/lib/_tsc.js:79564:32)
    at checkNonNullExpression (/Users/will/.nvm/versions/node/v22.11.0/lib/node_modules/typescript/lib/_tsc.js:73599:29)

🙂 Expected behavior

No crash

Additional information about the issue

No response

Activity

  1. Andarist commented on Nov 22, 2024

    @Andarist
    Contributor

    According to the provided bisect information it's caused by something in this diff.

    To fix this a repro case has to be provided though.

  2. epmatsw commented on Nov 22, 2024

    @epmatsw
    Author

    It doesn't show up in the UI for some reason, but in the console you can see an uncaught promise rejection:

    Image

  3. Andarist commented on Nov 22, 2024

    @Andarist
    Contributor

    It shouldn't happen but I'm not entirely convinced that it's a repro case for your original problem. This crashes when calling reportNonexistentProperty so it feels like an extra repro for #60336 (that said... a new one cause your issue is pretty new and that can be reproduced with older TS versions). I assume that you've wanted to report an issue for a code that doesn't error on 5.6.3. Once we add a missing property, this repro stops crashing: TS playground

  4. Andarist commented on Nov 22, 2024

    @Andarist
    Contributor

    The above repro is caused by the fact that typeFromObjectLiteral calls inferExpressionType nowadays despite !canGetTypeFromObjectLiteral(objectLiteral, context). Previously it bailed out of this function and just returned false in this case.

  5. cgockeln42 commented on Nov 25, 2024

    @cgockeln42

    We have a similar stacktrace and issue. With version 5.6.3 it is working and building but with the latest 5.7.2 its failing with the following stacktrace:

    node:internal/process/promises:289
                triggerUncaughtException(err, true /* fromPromise */);
                ^
    
    RangeError: Maximum call stack size exceeded
        at getJSDocType (D:\a\1\s\node_modules\typescript\lib\typescript.js:15151:22)
        at getEffectiveTypeAnnotationNode (D:\a\1\s\node_modules\typescript\lib\typescript.js:20389:91)
        at getContextualTypeForVariableLikeDeclaration (D:\a\1\s\node_modules\typescript\lib\typescript.js:75985:22)
        at getContextualTypeForObjectLiteralElement (D:\a\1\s\node_modules\typescript\lib\typescript.js:76477:69)
        at getContextualType2 (D:\a\1\s\node_modules\typescript\lib\typescript.js:76770:16)
        at getApparentTypeOfContextualType (D:\a\1\s\node_modules\typescript\lib\typescript.js:76689:120)
        at getContextualTypeForObjectLiteralElement (D:\a\1\s\node_modules\typescript\lib\typescript.js:76481:18)
        at getContextualTypeForObjectLiteralMethod (D:\a\1\s\node_modules\typescript\lib\typescript.js:76473:12)
        at getApparentTypeOfContextualType (D:\a\1\s\node_modules\typescript\lib\typescript.js:76689:58)
        at getContextualSignature (D:\a\1\s\node_modules\typescript\lib\typescript.js:77088:18)
    
  6. epmatsw commented on Dec 2, 2024

    @epmatsw
    Author

    Hmm. Interesting. It's definitely that line of code, commenting out the equivalent of [this.a]: "", in our codebase fixes the error. But it is puzzling that the stack is different here. Maybe it changed between 5.7 and 5.8? I can't tell with the minified stack for 5.7 in the playground :/

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

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions