TypeScript 5.1.3使用lodash的类型错误(类型示例化太深,可能是无限的)

tkclm6bt  于 2023-06-24  发布在  TypeScript
关注(0)|答案(1)|浏览(291)

我刚刚将我的Ionic/Angular项目更新为Angular 16.1.3,这里更相关的是TypeScript 5.1.3
我也有

  1. "lodash-es": "^4.17.21",
  2. "@types/lodash": "^4.14.195",
  3. "@types/lodash-es": "^4.17.7",

我现在在尝试运行时遇到以下错误...

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

第一个TS2589: Type instantiation is excessively deep and possibly infinite.,我不懂,字体一点都不深。看看我们刚刚得到的类型定义

  1. interface Object<T> extends LoDashImplicitWrapper<T> {
  2. }
  3. interface LoDashImplicitWrapper<TValue> {
  4. /**
  5. * @see _.invokeMap
  6. */
  7. invokeMap(methodName: string, ...args: any[]): Collection<any>;
  8. /**
  9. * @see _.invokeMap
  10. */
  11. invokeMap<TResult>(method: (...args: any[]) => TResult, ...args: any[]): Collection<TResult>;
  12. }

第二个错误似乎也与LoDashExplicitWrapper<T>有关。它声明了The types returned by 'entries().pop()' are incompatible between these types.,但上面看,在LoDashImplicitWrapper中没有名为entries()的属性,只有两个invokeMap方法。
有谁知道我为什么会犯这些奇怪的错误吗?

jaql4c8m

jaql4c8m1#

Typescript 5.1.3报告了一个错误问题https://github.com/microsoft/TypeScript/issues/54542
问题中提到的解决方案是将"skipLibCheck": true添加到tsconfig.json中。

相关问题