Search code examples
angulartypescriptlodash

TypeScript 5.1.3 Type errors with lodash (Type instantiation is excessively deep and possibly infinite)


I have just updated my Ionic/Angular project to Angular 16.1.3, and, more relevant here TypeScript 5.1.3.

I also have

  "lodash-es": "^4.17.21",
  "@types/lodash": "^4.14.195",
  "@types/lodash-es": "^4.17.7",

I am now getting the following errors when I try to run...

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

The first one TS2589: Type instantiation is excessively deep and possibly infinite., I don't get it, the type is not deep at all. Looking at the type definitions we just have

 interface Object<T> extends LoDashImplicitWrapper<T> {
 }

 interface LoDashImplicitWrapper<TValue> {
        /**
         * @see _.invokeMap
         */
        invokeMap(methodName: string, ...args: any[]): Collection<any>;
        /**
         * @see _.invokeMap
         */
        invokeMap<TResult>(method: (...args: any[]) => TResult, ...args: any[]): Collection<TResult>;
    }

The second error also seems to do with LoDashExplicitWrapper<T>. It states The types returned by 'entries().pop()' are incompatible between these types. but looking above there is no property called entries() in LoDashImplicitWrapper, there are just two invokeMap methods.

Why am I getting these bizarre errors?


Solution

  • There is a bug issue in Typescript 5.1.3 reported https://github.com/microsoft/TypeScript/issues/54542.

    Workaround solution mentioned in the issue is adding "skipLibCheck": true to the tsconfig.json.