Repository navigation
Stack overflow in TS 4.5.3 and nightly #47142
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Description
I'm running into a similar issue. When I run
tscon ournodeproject, I getRangeError: Maximum call stack size exceeded.Everything was working fine - this just happens when I attempt to upgrade to typescript
4.5.3. It works fine in typescript4.2.3.FWIW, recursive types should definitely be allowed. They're a standard part of any programming language (more generally, Context Free Grammars) and it's very common to do this (e.g. with datastructures like trees, or compilers, etc.).
e.g. it's 100% valid to have:
type Tree<T> = { data: T; children: Tree<T>[] }Unfortunately the stacktrace I get doesn't give me any indication of which type is causing the issue:
/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:94444 throw e; ^ RangeError: Maximum call stack size exceeded at getRelationKey (/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:54317:32) at recursiveTypeRelatedTo (/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:52985:26) at isRelatedTo (/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:52645:30) at typeRelatedToSomeType (/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:52869:35) at structuredTypeRelatedToWorker (/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:53099:32) at structuredTypeRelatedTo (/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:53084:30) at isRelatedTo (/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:52642:30) at checkTypeRelatedTo (/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:52314:26) at isTypeRelatedTo (/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:52276:24) at isTypeAssignableTo (/Users/cbattycapps/{REDACTED}/node_modules/typescript/lib/tsc.js:51558:20)
Originally posted by Charles Batty-Capps (@charlescapps) in #45576 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Activity
DanielRosenwasser commentedon Dec 14, 2021
If you open up
tsc.jsand add the following line to the top ofcheckTypeRelatedTothat might give you an indication of where things are going off the rails, and will help us come up with a repro and possible fix.
[-]Stack Overflow in TS 4.5.3 and nightly[/-][+]Stack overflow in TS 4.5.3 and nightly[/+]sloonz commentedon Dec 17, 2021
Simplest repro I could do :
package.json :
{"name":"tscbug","dependencies":{"objection":"^3.0.0","typescript":"^4.5.3"}}tsconfig.json (nothing fancy, generated by tsc --init) :
DanielRosenwasser commentedon Dec 17, 2021
Thank you for the repro! That'll help us expedite a fix, though a lot of people are going to be out for a bit, so please be patient.
ahejlsberg commentedon Jan 7, 2022
I bisected using the repro. This appears to be yet another casualty of #30639. That said, we should of course never overflow the stack. I can fix that, but when I do we now report an
Excessive stack depth comparing types 'UpsertGraphMethod<?>' and 'UpsertGraphMethod<?>'error. Effectively, attempting to compute variance for theUpsertGraphMethodtype ends up spiraling forever (because with #30639 we keep exploring assignability to a conditional type on the target side).ahejlsberg commentedon Jan 7, 2022
Wesley Wigham (@weswigham) Any ideas here?
ahejlsberg commentedon Jan 7, 2022
Actually, with a couple of minor fixes (without which the variance computation for
UpsertGraphMethodruns amok) the repro now compiles as it did with 4.2. I will put up a PR.