I upgraded my project from angular 6 to angular 7. I have a file upload component in my project. It gives a compiler error after the upgrade.
onUpload() {
const fileReader = new FileReader();
fileReader.onload = () => this.uploadFile(fileReader.result);
fileReader.readAsText(this.fileToUpload);
}
uploadFile(fileContent: string) {
//upload
}
In above code, this.uploadFile(fileReader.result) gives following error.
error TS2345: Argument of type 'string | ArrayBuffer' is not assignable to parameter of type 'string'
The type of fileReader.result is string | ArrayBuffer, and it says this cannot be assigned to a string. How can I convert string | ArrayBuffer type to a string?
fileReader.result as string?as string. Please add your comment as an answer.