如何修复 TypeScript 错误:TS2234:接口的所有声明必须具有相同的类型参数 [英] How do I fix the TypeScript error: TS2234: All declarations of an interface must have identical type parameters
本文介绍了如何修复 TypeScript 错误:TS2234:接口的所有声明必须具有相同的类型参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在打字稿 v0.9.5 中编译了这段代码.
In typescript v0.9.5 this code compiled.
interface Array {
indexOfField : (propertyName: string, value: any) => number;
}
升级到 typescript 1.0 后,出现以下错误:
After upgrading to typescript 1.0, I get the following error:
(2,11): 错误 TS2234:接口的所有声明必须具有相同的类型参数.
(2,11): error TS2234: All declarations of an interface must have identical type parameters.
第 2:11 行是关键字 Array.
Line number 2:11 is the keyword Array.
我该如何解决这个问题?
How do I fix this?
推荐答案
Array
的另一个定义是 Array
(带有类型参数)在 lib.d.ts
.您需要将您的声明声明为:
The other definition of Array
is Array<T>
(with a type parameter) in lib.d.ts
. You need to declare yours as:
interface Array<T> {
indexOfField : (propertyName: string, value: any) => number;
}
为了具有相同数量的类型参数.
in order to have the same number of type parameters.
这篇关于如何修复 TypeScript 错误:TS2234:接口的所有声明必须具有相同的类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文