microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.21k stars 12.51k forks source link

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

Open epmatsw opened 2 days ago

epmatsw commented 2 days ago

πŸ”Ž 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

Andarist commented 2 days ago

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.

epmatsw commented 2 days ago

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

epmatsw commented 2 days ago

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

Image

Andarist commented 2 days ago

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 https://github.com/microsoft/TypeScript/issues/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

Andarist commented 2 days ago

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.