读取 FileReader 中字符串的 TypeScript 错误
用于读取文件内容的简单代码:
const reader: FileReader = new FileReader();
reader.readAsText(file);
reader.onload = (e) => {
const csv: string = reader.result; -> getting TS error on this line
}
我收到的 TypeScript 错误:
Type 'string | ArrayBuffer' is not assignable to type 'string'.
Type 'ArrayBuffer' is not assignable to type 'string'.
reader.result
强制转换为string
。 - callback