无法覆盖/扩展Typescript中的类型

时间:2016-06-22 14:52:41

标签: javascript intellij-idea typescript

我遇到FileListDOMStringList阵列上的数组函数的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

为什么编译器不使用我的扩展接口?

0 个答案:

没有答案