TypeScript Version: 3.0.0-dev.20180707
Search Terms: dom, FileReader
Code
Taken directly from MDN: https://developer.mozilla.org/en-US/docs/Web/API/FileReader/onload
function onChange(event) {
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function(event) {
// The file's text will be printed here
console.log(event.target.result)
};
reader.readAsText(file);
}
Expected behavior:
No errors.
Actual behavior:
[ts] Property 'result' does not exist on type 'EventTarget'.
This is a regression, since there were no such errors reported in TS 2.9.2.
It looks like the regression was introduced in 7a7d04e126fb7c1c6074ef26657eddb0f32e4003
The behavior change was introduced in https://github.com/Microsoft/TSJS-lib-generator/pull/448. the PR switched to use the widl file to generate the .d.ts file for the File APIs. The widl does not seem to define the FileReaderProgressEvent (which was defined in the past). It is not clear if this is a spec bug, or an intentional change to the spec.
//cc @saschanaz
FileReaderProgressEvent is obsolete and replaced by ProgressEvent, as the PR says.
Interesting. So the spec intent is clear: the load event is fired on the context object, which is a FileReader, and the event's target points to the FileReader, so it has the result field.
The current declarations don't capture this, stating that we deal with a generic ProgressEvent, and its target property is naturally doesn't point to FileReader, and it doesn't have the result, which is a regression from the older declarations.
Yeah... I think this is related to https://github.com/Microsoft/TypeScript/issues/299.
@saschanaz maybe we should redefine the FileReaderProgressEvent for now.
Hi, any news on this? After updating typescript to 3.0 I am getting Cannot find name 'FileReaderProgressEvent'.
I would suggest using general ProgressEvent as no major browser supports FileReaderProgressEvent, including Edge, Firefox, and Chrome. @mhegazy, or maybe Microsoft/TSJS-lib-generator#560 should have covered this?
Hi. I introduced FileReaderProgressEvent in https://github.com/Microsoft/TSJS-lib-generator/pull/398 and found this issue today.
It is possible to have event.targer.result without FileReaderProgressEvent. The first commit https://github.com/Microsoft/TSJS-lib-generator/pull/398/commits/90971b1dca656bd17dc0f5a921b9435f063ad78d of the PR was implemented in such way. Can we use this?
It is possible to have event.targer.result without FileReaderProgressEvent. The first commit Microsoft/TSJS-lib-generator@90971b1 of the PR was implemented in such way.
I think Microsoft/TSJS-lib-generator#207 is better as its more general, readable, and easy to write. We may add ProgressEvent<T> first and see how things go.
Any progress on this one?
Any progress on this? What are we waiting on to get this fixed, as it's clearly been identified as a bug that needs fixing...
For now I worked around this with:
reader.onload = (event: ProgressEvent & FileReaderEvent) => { ...
It's too late to fix this for 3.5 but it needs to be fixed as soon as 3.6 development starts so people have a chance to test the new lib.dom.d.ts.
Most helpful comment
Any progress on this? What are we waiting on to get this fixed, as it's clearly been identified as a bug that needs fixing...