Skip to content

Regression with TS 5. Type instantiation is excessively deep and possibly infinite.ts(2589) #53514

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

Open
garronej opened this issue Mar 26, 2023 · 11 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@garronej
Copy link

garronej commented Mar 26, 2023

Bug Report

🔎 Search Terms

  • Type instantiation is excessively deep and possibly infinite.ts(2589)
  • Typescript 5.0.2
  • instantiationCount >= 5e6

🕗 Version & Regression Information

5.0.2 (Also tested with 5.1.0-dev.20230326)

Please keep and fill in the line that best applies:

  • This changed between versions 4.9.5 and 5.0.2

⏯ Playground Link

I created a reproduction repo with straight forward reproduction path:
https://github.com/garronej/typescript-v5-instantiationCount-bug-report

💻 Code

The problem is related to typescript 5 instantiating much more object than TS 4.
I know that the problem occurs when involving this framework that has complex type definitions.

🙁 Actual behavior

With TypeScript v5 project fail to compile with Type instantiation is excessively deep and possibly infinite.ts(2589).
Because the instantiationCount limit (5e6) is reached.
Increasing it by modifying TypeScript's source fixes it but intelissense becomes so slow it becomes impossible to work.

On MBP M1:

1679856587162212.mp4

🙂 Expected behavior

With TypeScript v4 it compiles and the devloppement experience is smooth:

Screen.Recording.2023-03-26.at.20.25.38.mov

Thanks to all the team, thanks for your great work!

@fatcerberus
Copy link

Increasing it by modifying TypeScript's source fixes it but intelissense becomes so slow it becomes impossible to work.

FWIW, this indicates the instantiation limit is correctly doing its job and the types involved need to be simplified.

@garronej
Copy link
Author

garronej commented Mar 27, 2023

@fatcerberus allright but everything was working fine before v5.
The same types definitions produced much much less instantiations!

The max instantationCount the reproduction repo produces:

  • in v4: 17813 for a threashold of 5000000, that's 0.35% of the threashold
  • in v5: 26955722 thats 5,39 times the threashold

@RyanCavanaugh
Copy link
Member

Given that the count was low before, this seems like a possible bug.

A reduced repro (i.e. one that doesn't need the entire linked type definition) would be extremely helpful if you're able to provide one.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Mar 30, 2023
@aspirisen
Copy link

I have faced the same issue - on version 5 I started getting instantiation errors.
Here is a playground. On v5 you have the error, if you will switch to v4 the error will go away.

I tried to create minimal example, but unfortunately the example still uses type-fest library.

@Ellebkey
Copy link

Ellebkey commented Jun 2, 2023

This just happened to me while deploying GitHub actions.

node_modules/@types/lodash/common/common.d.ts:194:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.

This happens with version 5.1.3. On version 5.0.4 works fine

@jonsagara
Copy link

Same issue as @Ellebkey when upgrading Microsoft.TypeScript.MSBuild from 5.0.4 to 5.1.3.

I'm not well-versed on TypeScript and node, but it looks like the lodash types might need to be updated?

C:\DevSomeCompany\SomeProject\src\SomeProject\node_modules\@types\lodash\common\common.d.ts(194,15): error TS2589: Build:Type instantiation is ex
cessively deep and possibly infinite. [C:\DevSomeCompany\SomeProject\src\SomeProject\SomeProject.csproj]
C:\DevSomeCompany\SomeProject\src\SomeProject\node_modules\@types\lodash\common\common.d.ts(206,15): error TS2430: Build:Interface 'ObjectChain<T
>' incorrectly extends interface 'LoDashExplicitWrapper<T>'. [C:\DevSomeCompany\SomeProject\src\SomeProject\SomeProject.csproj]

@throrin19
Copy link

Same problem here with lodash types :

../../node_modules/@types/lodash/common/common.d.ts(194,15): error TS2589: Type instantiation is excessively deep and possibly infinite.
       ../../node_modules/@types/lodash/common/common.d.ts(206,15): error TS2430: Interface 'ObjectChain<T>' incorrectly extends interface 'LoDashExplicitWrapper<T>'.
         The types returned by 'entries().pop()' are incompatible between these types.
           Type 'CollectionChain<string | T[keyof T]>' is missing the following properties from type 'ObjectChain<[string, any]>': assign, assignIn, assignInWith, assignWith, and 11 more.

@stryaponoff
Copy link

I have this issue with 5.1.6 and 5.2.2. Still forced to using 5.0.4

@jakebailey
Copy link
Member

jakebailey commented Aug 29, 2023

I have this issue with 5.1.6 and 5.2.2. Still forced to using 5.0.4

This issue appears to be about a problem introduced in 5.0; if you are pinning to 5.0, then your issue started in 5.1 and can't be the same as this one. It'd be good to file a new issue with a reproduction of your own.

(The same goes to others in this thread.)

@jakebailey
Copy link
Member

FWIW the original issue (the new error and large instantiation count) bisects to #52392. This isn't the first time this has shown up; note the crosslinked issues on the PR page.

@ahejlsberg you might be interested, though I recall this was somewhat expected.

@geoffreytools
Copy link

It also causes issues with typed higher kinded types in some higher order scenarios

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

10 participants