首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >类型“Set<unknown>”只能在使用“--降级iterated”标志或使用“es2015”或更高的“--目标”时迭代。

类型“Set<unknown>”只能在使用“--降级iterated”标志或使用“es2015”或更高的“--目标”时迭代。
EN

Stack Overflow用户
提问于 2022-07-24 15:06:05
回答 3查看 3K关注 0票数 2

我正在尝试获取数组中的所有ids,然后使用React删除重复的ids。

这是我的代码:

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
{
  "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"
  ]
}

知道我为什么一直犯这个错误吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2022-10-22 18:59:16

同样的错误,将tsconfig.json从CommonJS设置为Es模块,使用目标模块,模块,moduleResolution帮助我。

我的tsconfig.json:

代码语言:javascript
运行
复制
    "compilerOptions": {
        "target": "ES2020",
        "module": "ESNext",
        "moduleResolution": "NodeNext",
        "jsx": "react-jsx",
        "baseUrl": "./",
        "resolveJsonModule": true,
        "esModuleInterop": true
    }
} 
票数 0
EN

Stack Overflow用户

发布于 2022-11-29 12:18:45

问题是,您希望使用仅在ES2015 JavaScript版本之前可用的特性。

解决方案是更新tsconfig.json文件,将"target"更改为至少"es2015" (也称为"es6")。

代码语言:javascript
运行
复制
{
  "compilerOptions": {
    "target": "es2015",
    ...
  }
}

来源:TSConfig目标选项

票数 0
EN

Stack Overflow用户

发布于 2022-09-01 07:43:10

修改ts配置文件

代码语言:javascript
运行
复制
...
"target": "ES2015",
"lib": [...,"ES2015"],
...
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73099543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档