【发布时间】:2019-03-28 02:02:09
【问题描述】:
从 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。
标签: javascript typescript arraybuffer