TypeScript: 5.1 regression from 5.0: JavaScript heap out of memory (Type instantiation is excessively deep and possibly infinit)
Bug Report
5.0.4
used to work fine after upgrading to the current latest version 5.1.3
. Very slow builds and eventually crashes. My root-cause seems to be a circular issue of some sort with tsc.
Seems like tsc can’t handle interface definition files anymore, in this case from lodash
?
node_modules/@types/lodash/common/common.d.ts:194:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.
194 interface Object<T> extends LoDashImplicitWrapper<T> {
~~~~~~
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.
206 interface ObjectChain<T> extends LoDashExplicitWrapper<T> {
~~~~~~~~~~~
My workaround was adding "skipLibCheck": true
to the tsconfig.json did mitigate the issue for now.
node_modules/@types/lodash/common/common.d.ts:194:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.
194 interface Object<T> extends LoDashImplicitWrapper<T> {
~~~~~~
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.
206 interface ObjectChain<T> extends LoDashExplicitWrapper<T> {
~~~~~~~~~~~
Workaround for me was to add: "skipLibCheck": true
to the tsconfig.json did mitigate the issue for now.
🔎 Search Terms
- Crash
- OOME
- 5.1
- Heap
🕗 Version & Regression Information
I also tried the latest next
tag, with the same issues.
- This is a crash
- This changed between versions 5.0.x and 5.1.x
⏯ Playground Link
The “Type is excessively deep” is being triggered in a project that includes this the @types/lodash
, so in your package.json be sure you have the dependency:
"dependencies": {
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/lodash": "^4.14.195"
}
Be sure that you did NOT set skipLibCheck
to true
. So keep it to false, otherwise the d.ts
files will be ignored.
Execute via: NODE_OPTIONS=--max-old-space-size=8192 tsc --pretty --diagnostics --extendedDiagnostics --incremental false
💻 Code
See below, it doesn’t involve my code.
🙁 Actual behavior
JavaScript heap out of memory, because of circular/ too deep dependency?
node_modules/@types/lodash/common/common.d.ts:194:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.
194 interface Object<T> extends LoDashImplicitWrapper<T> {
~~~~~~
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.
206 interface ObjectChain<T> extends LoDashExplicitWrapper<T> {
~~~~~~~~~~~
Found 2 errors in 1 file.
Errors Files
2 node_modules/@types/lodash/common/common.d.ts:194
Files: 253
Lines of Library: 9875
Lines of Definitions: 73521
Lines of TypeScript: 3999
Lines of JavaScript: 0
Lines of JSON: 0
Lines of Other: 0
Identifiers: 117524
Symbols: 4856905
Types: 1093043
Instantiations: 11883895
Memory used: 2379915K
Assignability cache size: 230447
Identity cache size: 772
Subtype cache size: 398
Strict subtype cache size: 10
I/O Read time: 0.15s
Parse time: 1.17s
ResolveModule time: 0.21s
ResolveTypeReference time: 0.03s
ResolveLibrary time: 0.02s
Program time: 1.70s
Bind time: 0.47s
Check time: 239.51s
transformTime time: 0.05s
Source Map time: 0.02s
commentTime time: 0.04s
I/O Write time: 0.02s
printTime time: 0.37s
Emit time: 0.37s
Total time: 242.05s
🙂 Expected behavior
No crashes or errors during tsc
!
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 40
- Comments: 19 (9 by maintainers)
Commits related to this issue
- update dependencies typescript is pinned to 5.0.x because of the following issue: https://github.com/microsoft/TypeScript/issues/54542 — committed to Oppzippy/recruitment-bot by Oppzippy a year ago
- fix: revert ts to 5.0.4 [microsoft/TypeScript#54542] — committed to megasanjay/vue3-lottie by megasanjay a year ago
- fix: revert ts to 5.0.4 [microsoft/TypeScript#54542] — committed to megasanjay/vue3-marquee by megasanjay a year ago
- Update TypeScript to 5.0.4 Newer versions have a regression and fail to type check at the moment. https://github.com/microsoft/TypeScript/issues/54542 — committed to jgosmann/adventures by jgosmann a year ago
- Update TypeScript to 5.0.4 Newer versions have a regression and fail to type check at the moment. https://github.com/microsoft/TypeScript/issues/54542 — committed to jgosmann/adventures by jgosmann a year ago
- to fix the build quill version ^2.0.0-dev.4 works, later version such as rc1 and rc2 requires react-quill changes. upgraded typescript to 5.2.2 to fix issues with lodash https://github.com/microsoft/T... — committed to naveennazimudeen/react-quill by deleted user 4 months ago
Any update on this? Got the same issue when upgrading to typescript 5.1.3 from 4.9.4 and we have @types/lodash : 4.14.195 as devdependencies.
Any chance to fix this? 3 weeks after issue was reported.
My workaround for now is to disable interfaces (.d.ts files), using the following code snippet in my local
tsconfig.json
file:More info: https://www.typescriptlang.org/tsconfig#skipLibCheck
Can people following the thread verify that https://github.com/microsoft/TypeScript/pull/54781 fixes the issue? You can do so by using a specific build of TypeScript:
(see https://github.com/microsoft/TypeScript/pull/54781#issuecomment-1607903315)
Bisected to https://github.com/microsoft/TypeScript/pull/52106
Important to mention that it is a just temporary workaround as it would skip all libraries check.
Same problem with lodash here but with
skipLibCheck
totrue
. Any news about this resolution ?It works fine with typescript
5.0.4
This is my error :
@DanielRosenwasser confirmed https://github.com/typescript-eslint/typescript-eslint/pull/7088/ appears to be fixed, thanks!
I can repo this with a simple single-file project that just imports
@types/lodash
, but only whenstrict
mode is disabled:No problems when compiling with
--strict
enabled. The runaway type check happens when computing variance information for typeObjectChain<T>
. A quick workaround is to change one of the declarations ofObjectChain<T>
toObjectChain<in out T>
. This asserts that the type is invariant which skips the variance computation.