我试图获取数组中的所有 id,然后使用 React TypeScript 删除重复项。
这是我的代码:
const uniqueMuscle = workoutexercices.map((exercice: any) => {
let exercicesId = exercice.id;
exercicesId = [...new Set(exercicesId)];
return exercicesId;
});
Run Code Online (Sandbox Code Playgroud)
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, …Run Code Online (Sandbox Code Playgroud) 我正在阅读文档并了解到 React仅StrictMode用于开发,它解释了为什么我们有双重调用。
这很好,但这是否意味着我必须StrictMode为我的生产禁用手动功能,或者反应build命令是否会自行执行此操作?