Skip to content

Regression from 4.2 to 4.3 : RangeError: Maximum call stack size exceeded #45632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JSteunou opened this issue Aug 30, 2021 · 12 comments
Closed
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@JSteunou
Copy link

Bug Report

Since TypeScript 4.3 we are unable to run TypeScript check on our projet (more than 10.000 ts modules)
We are trying to upgrade from TypeScript 4.0 to 4.4 and stuck on 4.2

The error is quite generic RangeError: Maximum call stack size exceeded

If there is a way to get more log or to see which module trigger this behavior it would help a lot!

Maybe close to #44281?

🔎 Search Terms

  • 4.3
  • 4.4
  • RangeError: Maximum call stack size exceeded
  • Circular dependency
  • Recursive

🕗 Version & Regression Information

  • This changed between versions 4.2 and 4.3 (still present in next / 4.5-dev)

⏯ Playground Link

Sorry no playground I'm unable to isolate the part linked to the bug

💻 Code

// We can quickly address your report if:
//  - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!
//  - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.
//  - The incorrectness of the behavior is readily apparent from reading the sample.
// Reports are slower to investigate if:
//  - We have to pare too much extraneous code.
//  - We have to clone a large repo and validate that the problem isn't elsewhere.
//  - The sample is confusing or doesn't clearly demonstrate what's wrong.

🙁 Actual behavior

 tsc --noEmit --project tsconfig.ci.json
/project/node_modules/typescript/lib/tsc.js:90672
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at checkExpressionWorker (/project/node_modules/typescript/lib/tsc.js:62461:39)
    at checkExpression (/project/node_modules/typescript/lib/tsc.js:62428:38)
    at getTypeOfExpression (/project/node_modules/typescript/lib/tsc.js:62382:24)
    at getMatchingUnionConstituentForObjectLiteral (/project/node_modules/typescript/lib/tsc.js:54126:40)
    at discriminateContextualTypeByObjectMembers (/project/node_modules/typescript/lib/tsc.js:56777:20)
    at getApparentTypeOfContextualType (/project/node_modules/typescript/lib/tsc.js:56789:93)
    at getContextualTypeForObjectLiteralElement (/project/node_modules/typescript/lib/tsc.js:56696:24)
    at getContextualType (/project/node_modules/typescript/lib/tsc.js:56855:28)
    at hasContextualTypeWithNoGenericTypes (/project/node_modules/typescript/lib/tsc.js:55760:17)
    at getNarrowableTypeForReference (/project/node_modules/typescript/lib/tsc.js:55766:53)
error Command failed with exit code 1.

🙂 Expected behavior

no error :)

@andrewbranch
Copy link
Member

Possibly related/duplicate #45576

@andrewbranch andrewbranch changed the title Regression from 4.3 : RangeError: Maximum call stack size exceeded Regression from 4.2 to 4.3 : RangeError: Maximum call stack size exceeded Aug 30, 2021
@andrewbranch
Copy link
Member

Ah, if it's happening in 4.3 it's more likely related to #44281

@andrewbranch
Copy link
Member

If there is a way to get more log or to see which module trigger this behavior it would help a lot!

You should be able to get some info by following the tracing instructions in the wiki: https://github.com/microsoft/TypeScript/wiki/Performance-Tracing

Let us know if that helps you solve the problem or create a repro.

@andrewbranch andrewbranch added the Needs More Info The issue still hasn't been fully clarified label Aug 30, 2021
@JSteunou
Copy link
Author

Thank you @andrewbranch for the hints. Looking at #44281 it is closed, but my issue is still happening in @next (4.5-dev) version so either the fix is not really merged yet, or this issue is not related :/

Will continue to debug / trace today

@andrewbranch
Copy link
Member

One common root cause of #44281 was fixed, but it has become clear there are more, but we haven’t been able to identify common patterns yet. Really hoping your tracing session helps us figure it out 😄

@JSteunou
Copy link
Author

JSteunou commented Sep 1, 2021

Ok we succeed to isolate the issue in our base code, but it is very hard yet to reproduce it in a playground.

To sum it up, there are 2 files involved, one full of type def, the second with types & components. There is some circular dep because the 1st import some types from the second, and the second import some types from the 1st. Checking those files with tsc separately does not trigger the error, BUT, here is the issue, when those two modules are imported together in another module, then 💥

@ahejlsberg
Copy link
Member

@JSteunou I'm pretty sure this is fixed by #46354 which will be in tomorrow's nightly build. Can you verify for us?

@JSteunou
Copy link
Author

sure, will give it a try

@boeckMt
Copy link

boeckMt commented Oct 22, 2021

I have a similar Issue

Typescript version

$ npx tsc -V
Version 4.1.6

I can't figure out the root cause, but could create a small file to reproduce the error.

// test-call-stack.ts

interface Dimension {
  values: `${string},` | null;
}

function getTimeValueFromDimensions(dim: Dimension) {
  const input = dim.values;
  if (!input) {
    console.log('is null');
  }
}

getTimeValueFromDimensions({values: null});
// npx tsc test-call-stack.ts
.../tsc.js:87014
  throw e;
  ^
  RangeError: Maximum call stack size exceeded
  at getBaseConstraintOfType (.../tsc.js:43728:22) // or getBaseConstraintOfType (.../tsc.js:43727:41)
  ...

The error is not there if the function is as follows

function getTimeValueFromDimensions(dim: Dimension) {
  const input = dim.values;
  console.log(input);
}

@andrewbranch
Copy link
Member

andrewbranch commented Oct 22, 2021

4.1 is super old... that sample was fixed in 4.2. Not the same issue.

@JSteunou
Copy link
Author

JSteunou commented Nov 3, 2021

@ahejlsberg tested with 4.5.0-dev.20211101 and the issue is gone! Good job thank you 👍

@JSteunou JSteunou closed this as completed Nov 3, 2021
@andrewbranch
Copy link
Member

@JSteunou thanks for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

4 participants