Skip to content
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

[regression] recursive like types => maximum call stack error #38825

Closed
lifaon74 opened this issue May 28, 2020 · 4 comments
Closed

[regression] recursive like types => maximum call stack error #38825

lifaon74 opened this issue May 28, 2020 · 4 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@lifaon74
Copy link

TypeScript Version: 3.9.x and 4.0.0

Search Terms: maximum call stack, recursive type

Code

On one of my big projet, migrating from typescript 3.8.3 to 3.9.3 broke many things:

  • "circular constraint" errors appeared. I need some kind of circular reference to check if a Generic type matches a specific pattern
  • "maximum call stack" error when building the project (simply running tsc)

Expected behavior:
should transpile

Related Issues:
#37475
#38198

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 4, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone Jun 4, 2020
@weswigham
Copy link
Member

The crash looks to be fixed by #38904 (meaning the crash is probably similar in nature or exactly the issue with the updated definition of Array.prototype.flat shipped in 3.9). After that it looks like you just have a lot of newly detected circularities in generic constraints, like TKVMap extends TFiniteStateKeyValueMapConstraint<TValue, TFinalState, TKVMap>, where in TFiniteStateKeyValueMapConstraint, TKVMap meaningfully is supposed to determine the output shape. IIRC, this is new because in 3.9 we now actually can flag circularities arising as a result of mapped type creation (which is how TKVMap is eventually used recursively - in a mapped type), where prior to 3.9 we'd fail to flag these (and instead silently use an empty object type). The new behavior is more complete, as previously we were essentially failing to check these constraints.

@kasperisager
Copy link

I'm seeing stack overflows for recursive types like the following in both 3.9 and nightly:

type N<T, K extends string> = T | { [P in K]: N<T, K> }[K];

type M = N<number, "M">;

Playground Link

@weswigham
Copy link
Member

@kasperisager mind opening a new issue for yours? That's definitely a good repro of a crash distinct from the one in the OP here (which is fixed). The OP's crash was in node building, while yours is in instantiation itself.

@kasperisager
Copy link

Not at all, I'll open a new issue ASAP 👍 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants