javascriptangularhtmltypescripthtml5-filesystem

Typescript HTML5 API Typings


Anyone know if there exists type definitions for the HTML5 File API? Specifically:

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.


Solution

  • I cannot tell you why File and FileReader are not included on the Window object already. You can certainly open an issue with typescript to see if they plan on adding them. In the meantime, the easiest way to "patch" this oversight would be to use declaration merging.

    Window.d.ts

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

    Now File and FileReader will be available on the Window object anywhere in your project.