【发布时间】:2019-04-28 23:35:23
【问题描述】:
我遇到了这个恼人的 TypeScript 错误:
错误 TS2488:类型“{}”必须具有返回迭代器的“Symbol.iterator”方法。
正如您在我的代码中看到的,我使用的是扩展运算符。经过一些研究,我发现我必须将 mytsconfig.json 更新为 "target": "es6" 但没有任何改变。我错过了什么?
功能
formatFileName(e) {
let files = e.target.files;
this.test = Array.from(files).reduce((acc, cur) => [
...acc, {
name: cur.name.replace(/^.*\\/, "")
}
], [])
}
TS 配置
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
TS CONFIG APP(如果有帮助)
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": [],
"moduleResolution": "node",
"target": "es6",
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
【问题讨论】:
-
无法使用您提供的
tsconfig重现您的问题 -
所以你的意思是问题不在我的tsconfig?也许是我正在使用的 Webstorm?
-
不确定问题出在哪里。我会尝试在 IDE 之外运行编译器,看看是否是 IDE 问题。我在 VSCode 中使用了你的 tsconfig,它似乎可以工作
-
好的,我已经更新了问题,表明它可能是由 Webstorm 引起的。我也试试你的建议,谢谢
标签: angular typescript ecmascript-6 webstorm