【问题标题】:How do I fix the TypeScript error: TS2234: All declarations of an interface must have identical type parameters如何修复 TypeScript 错误:TS2234:接口的所有声明必须具有相同的类型参数
【发布时间】:2023-03-21 09:30:01
【问题描述】:

在 typescript v0.9.5 中编译了此代码。

interface Array {
    indexOfField : (propertyName: string, value: any) => number;
 }

升级到 typescript 1.0 后,出现以下错误:

(2,11):错误 TS2234:接口的所有声明必须具有相同的类型参数。

行号 2:11 是关键字 Array。

我该如何解决这个问题?

【问题讨论】:

    标签: typescript


    【解决方案1】:

    Array 的另一个定义是lib.d.ts 中的Array<T>(带有类型参数)。您需要将您的声明为:

    interface Array<T> {
        indexOfField : (propertyName: string, value: any) => number;
    }
    

    为了有相同数量的类型参数。

    【讨论】:

      猜你喜欢
      • 2019-09-04
      • 1970-01-01
      • 2022-09-30
      • 2017-08-13
      • 2018-11-11
      • 2021-05-29
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多