Reputation: 517
I am experiencing this annoying TypeScript error:
error TS2488: Type '{}' must have a 'Symbol.iterator' method that returns an iterator.
As you can see in my code I am using the spread operator. After some researches I have found that I had to update mytsconfig.json
with "target": "es6"
but nothing changed. What am I missing?
Function
formatFileName(e) {
let files = e.target.files;
this.test = Array.from(files).reduce((acc, cur) => [
...acc, {
name: cur.name.replace(/^.*\\/, "")
}
], [])
}
TS CONFIG
{
"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 (if it helps)
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": [],
"moduleResolution": "node",
"target": "es6",
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
Upvotes: 1
Views: 2452
Reputation: 517
I fixed the issue. I noticed that in 'lib' tsconfig.json file "es2015" wasn't indicated (as suggested inthis answer), but that, for some reason, didn't change anything.
So I went up to the function 'formatFileName(e)' and assigned to this.test the array of files, and just after this declaration I applied the reduce function to do my operations.
FIXED FUNCTION
formatFileName(e) {
let files = e.target.files;
this.test = Array.from(files)
this.test.reduce((acc, cur) => [
...acc, {
name: cur.name.replace(/^.*\\/, "")
}
], [])
}
Upvotes: 0