我遇到FileList
和DOMStringList
阵列上的数组函数的ts编译器错误问题。
(83,34): error TS2339: Property 'forEach' does not exist on type 'FileList'.
我尝试通过扩展类似这样的类型来覆盖lib.d.ts
中的默认类型:
interface FileList {
length: number;
item(index: number): File;
[index: number]: File;
filter(callback: Function, thisArg?: any);
find(callback: Function, thisArg?: any);
findIndex(callback: Function, thisArg?: any);
forEach(callback: Function);
indexOf(searchElement: any, fromIndex?: any);
push(elements: any);
sort(compareFunction: Function);
}
declare var FileList: {
prototype: FileList;
new(): FileList;
};
interface DOMStringList {
length: number;
contains(str: string): boolean;
item(index: number): string;
[index: number]: string;
filter(callback: Function, thisArg?: any);
find(callback: Function, thisArg?: any);
findIndex(callback: Function, thisArg?: any);
forEach(callback: Function);
indexOf(searchElement: any, fromIndex?: any);
push(elements: any);
sort(compareFunction: Function);
}
declare var DOMStringList: {
prototype: DOMStringList;
new(): DOMStringList;
}
IntelliJ正确链接到我的ts-fixes.d.ts
文件,并没有将.forEach
突出显示为缺失属性。
但是,编译器仍抱怨我的forEach
类型上缺少属性FileList
。
为什么编译器不使用我的扩展接口?