我正在尝试获取数组中的所有ids,然后使用React删除重复的ids。
这是我的代码:
const uniqueMuscle = workoutexercices.map((exercice: any) => {
let exercicesId = exercice.id;
exercicesId = [...new Set(exercicesId)];
return exercicesId;
});
VSCode用红色标记[...new Set(exercicesId)];
并告诉我:Type 'Set<unknown>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher
因此,我去了我的ts.config
,我更改了值,但仍然是相同的错误。
这是我的ts.config
:
{
"compilerOptions": {
"target": "es2015",
I "downlevelIteration": true
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
知道我为什么一直犯这个错误吗?
发布于 2022-10-22 18:59:16
同样的错误,将tsconfig.json从CommonJS设置为Es模块,使用目标模块,模块,moduleResolution帮助我。
我的tsconfig.json:
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "NodeNext",
"jsx": "react-jsx",
"baseUrl": "./",
"resolveJsonModule": true,
"esModuleInterop": true
}
}
发布于 2022-11-29 12:18:45
问题是,您希望使用仅在ES2015 JavaScript版本之前可用的特性。
解决方案是更新tsconfig.json文件,将"target"
更改为至少"es2015"
(也称为"es6"
)。
{
"compilerOptions": {
"target": "es2015",
...
}
}
来源:TSConfig目标选项
发布于 2022-09-01 07:43:10
修改ts配置文件
...
"target": "ES2015",
"lib": [...,"ES2015"],
...
https://stackoverflow.com/questions/73099543
复制相似问题