Installing FileReaderSync in Angular2

南楼画角 提交于 2021-02-08 19:39:14

问题


How do I install FileReaderSync in Angular2?

It appears in the file node_modules/typescript/lib/lib.webworker.d.ts but not can use it.

The FileReader I can use it without having to import anything.

I need to do something different with FileReaderSync?

error TS2304: Cannot find name 'FileReaderSync'.


回答1:


I had the same issue few months ago, the solution was to write custom typings.

main.bowser.d.ts

interface FileReaderSync {
  readAsArrayBuffer(blob: Blob): any;
  readAsBinaryString(blob: Blob): void;
  readAsDataURL(blob: Blob): string;
  readAsText(blob: Blob, encoding?: string): string;
}

declare var FileReaderSync: {
  prototype: FileReaderSync;
  new(): FileReaderSync;
};

and include them when you bootstrap angular2

// <reference path="./main.browser.d.ts" />

I wrote an article about this just now :D http://icode.co/angular2/php/2016/12/21/async-file-streaming-from-JS-to-PHP-WebWorkers.html



来源:https://stackoverflow.com/questions/39807671/installing-filereadersync-in-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!