Installing FileReaderSync in Angular2

How to install FileReaderSyncin Angular2?

It appears in the file node_modules/typescript/lib/lib.webworker.d.tsbut cannot use it.

FileReader I can use it without importing anything.

Do I need to do something different with FileReaderSync?

error TS2304: Cannot find name 'FileReaderSync'.

enter image description here

+4
source share
1 answer

I had the same problem a 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 turn them on when loading 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

+3
source

Source: https://habr.com/ru/post/1656458/


All Articles