简体   繁体   English

打字稿 HTML5 API 类型

[英]Typescript HTML5 API Typings

Anyone know if there exists type definitions for the HTML5 File API?有人知道 HTML5 文件 API 是否存在类型定义吗? Specifically:具体来说:

  • FileList文件列表
  • File文件
  • Blob斑点
  • FileReader文件阅读器

Also in Angular there is a document.defaultView object that represents the window, but it does not the full Window interface with respect to the Html5 File API, so it would be necessary to cast document.defaultView to an instance that has the Window interface for the file API.同样在 Angular 中有一个document.defaultView对象代表窗口,但它没有关于 Html5 File API 的完整 Window 接口,因此有必要将document.defaultView转换为具有Window接口的实例文件 API。

I cannot tell you why File and FileReader are not included on the Window object already.我不能告诉你为什么FileFileReader没有包含在Window对象中。 You can certainly open an issue with typescript to see if they plan on adding them.你当然可以用typescript打开一个问题,看看他们是否打算添加它们。 In the meantime, the easiest way to "patch" this oversight would be to use declaration merging.同时,“修补”这种疏忽的最简单方法是使用声明合并。

Window.d.ts窗口.d.ts

interface Window {
    File?:File;
    FileReader?:FileReader;
}

Now File and FileReader will be available on the Window object anywhere in your project.现在FileFileReader将在项目中任何位置的Window对象上可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM