1

According to https://developer.mozilla.org/en-US/docs/Web/API/FileReader

interface FileReader extends MSBaseReader {
    error: DOMError;
    readAsArrayBuffer(blob: Blob): void;
    readAsDataURL(blob: Blob): void;
    readAsText(blob: Blob, encoding?: string): void;
}
declare var FileReader: {
    prototype: FileReader;
    new (): FileReader;
}

this from lib.d.ts should also have DONE,LOADING,EMPTY on the variable. How can I extend this, and do lib.d.ts has a public place where such changes can be committed to?

2 Answers 2

4

To get access to new properties before they are added to lib.d.ts you can extend the declarations. This can be done because interfaces in TypeScript are open.

So add a TypeScript file called something like libextensions.ts and add the following:

interface FileReader {
    EMPTY: number;
    LOADING: number;
    DONE: number;
}

You only need to put the missing bits here - they will be added to the lib.d.ts interface.

You can use this technique to stay up to date with working drafts and the compiler will tell you when lib.d.ts has been updated by issuing a duplicate declaration error.

If you have an instance of a FileReader, you don't need to access the constant via FileReader.prototype.DONE you can use the constant on the instance - example:

var fileReader = new FileReader();
var example = fileReader.DONE;
Sign up to request clarification or add additional context in comments.

3 Comments

Problem was that I was converting some existing javascript and it had FileReader.DONE, so to use that I had to add it to the variable FileReader and not the interface. (realized I should do FileReader.prototype.DONE instead - its already there)
If you have an instance of a file reader, you don't need to go via the prototype - I have added an example to my answer - and indeed it is already available in TypeScript: typescriptlang.org/Playground/…
I have been thinking that DONE was like a static type on FileReader. Just need to get used to the way javascript works.
0

You should open a bug report here : http://typescript.codeplex.com/workitem/list/basic The typescript team manages lib.d.ts

1 Comment

I was a little fast, found out the DONE was on the prototype.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.