typescript - 如何使用意外令牌解决 ESLint 错误?
问题描述
我正在使用 Vue/TS 应用程序来读取 JSON 并比较它们。但我有一个 linter 错误。
这是错误:
319:33 错误解析错误:意外的令牌。你是说
{'>'}
还是>
?
第 319:33 行是我在下面的代码中检查文件长度的行:
handleFileInput(e:Event) {
const target:HTMLInputElement = <HTMLInputElement>e.target
const id:string = target?.id
console.log(id)
const files:FileList|null = target.files
if (files && files?.length > 0) {
const file = files[0]
const reader = new FileReader()
reader.onload = () => {
const res = JSON.parse(<string>reader.result)
if (id === "fileBr") {
this.br.json = res
this.br.name = file.name
} else if (id === 'fileC') {
this.c.json = res
this.c.name = file.name
}
}
reader.readAsText(file)
}
},
有人知道 es-lint 是否存在代码问题或配置错误?
谢谢
解决方案
我刚刚发现!
我应该使用: reader.result 作为字符串而不是 reader.result
这就是为什么我有意想不到的令牌
推荐阅读
- network-programming - 如果管道包含元素 tcpclientsink + tcpclientsrc,GStreamer RTSP 服务器不输出视频
- html - 如何使标签和输入的长度都相同?
- flutter - 在用户选择的工作日重复警报
- android - DialogFragment 在 android 中的 Fragment 延迟 2 秒后显示
- python - 为特定范围内的值索引列表
- angular - APP_INITIALIZER 解决后运行 JwtModule factory
- c# - MondoDB+C#+IQueryable - 有一个字符串数组以及如何在 Where 子句中将其加入 Mongo 的集合
- glsl - UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout
- javascript - 如何监听和等待节点中的变量变化?
- python - 如何在条形下方绘制网格线以及在所有内容之上绘制线条和线条