I have a piece of code that reads the contents of a locally stored file. Here is what it looks like:
onFile(event: any) {
console.log(event);
const file = event.target.files[0];
const reader = new FileReader();
reader.onloadend = (ev: any) => { console.log(ev); };
reader.readAsText(file);
}
After examining the console outputs, I noticed that the types being printed out are Event and ProgressEvent. So, I decided to adjust my methods to match the parameter types accordingly:
onFile(event: Event) {
console.log(event);
const file = event.target.files[0];
const reader = new FileReader();
reader.onloadend = (ev: ProgressEvent) => { console.log(ev, $event.target.result); };
reader.readAsText(file);
}
Despite making these changes, TsLint still raises warnings about files[0] and result not being present in their types. Have I specified the incorrect type for the operations? What would be the appropriate type to use in this scenario?