当前位置:网站首页>Use compiler option ‘--downlevelIteration‘ to allow iterating of iterators 报错解决
Use compiler option ‘--downlevelIteration‘ to allow iterating of iterators 报错解决
2022-06-11 11:28:00 【Michael18811380328】
Use compiler option '--downlevelIteration' to allow iterating of iterators 报错解决
最近在一个项目中使用 TS 做单元测试,界面报错如下:

报错分析
具体报错信息如下:Set<number> 不是数组或者字符串类型,不能使用扩展运算符。
error TS2569: Type 'Set<number>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
let newArr:number[] = [...new Set(nums)].sort((a, b) => a - b);百度后,其他网友也报类似的错误,Map 或者 Set 不能直接使用扩展运算符
TS2569: Type 'Map' is not an array type or a string type. Use compiler. option '- downlevellteration' to allow iterating of iterators.
解决方案1
按照官方提示,设置 '--downlevelIteration' 是 true,允许以“ ES5”或“ ES3”为目标时,在“ for-of”,传播、解构中为可迭代项提供支持。
把 tsconfig.json 配置文件修改一下即可
{
"compilerOptions": {
/* Basic Options */
"downlevelIteration": true,
/* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
}解决方案2
配置 dom.iterable 和 downlevelIteration 就可以正常运行
tsconfig.json
{
/*当目标是ES5或ES3的时候提供对for-of、扩展运算符和解构赋值中对于迭代器的完整支持*/
"downlevelIteration": true,
"lib": [
"dom",
"es5",
"es6",
"es7",
"dom.iterable"
]
}设置 target=es6 的时候,就能正常执行。原因:
注意:如果未指定--lib,则会注入默认的库列表。注入的默认库是: ► For --target ES5: DOM,ES5,ScriptHost ► For --target ES6: DOM,ES6,DOM.Iterable,ScriptHost
参考链接
边栏推荐
- An introduction to creating VOC datasets or Yolo datasets using labelimg
- 发布WordPress数据库缓存插件:DB Cache Reloaded 3.1
- WordPress database cache plug-in: DB cache Reloaded
- 在毕设中学习02——numpy多维数组的切片,形态变化,维度交换
- [file upload vulnerability 06] server file content detection and bypass experiment + image horse production method (based on upload-labs-14 shooting range)
- Cap theory sounds very big, but it's actually very simple
- 李飞飞:我更像物理学界的科学家,而不是工程师|深度学习崛起十年
- WordPress landing page beautification plug-in: recommended by login Designer
- 让WordPress支持注册用户上传自定义头像功能
- 导师转我800块,让我仿真一个电路(电源设计)
猜你喜欢

Cap theory sounds very big, but it's actually very simple
![my.cnf中 [mysql]与[mysqld] 的区别 引起的binlog启动失败的问题](/img/bd/a28e74654c7821b3a9cd9260d2e399.png)
my.cnf中 [mysql]与[mysqld] 的区别 引起的binlog启动失败的问题

Node connects to MySQL database and writes fuzzy query interface

不做伪工作者

msf cs openssl流量加密

Intermediate web development engineer, interview questions + Notes + project practice

2022 | framework for Android interview -- Analysis of the core principles of binder, handler, WMS and AMS!

再不刷题就晚了,最全的BAT大厂面试题整理

Display of receiving address list 【 project mall 】

Interview experience of Xiaomi Android development post~
随机推荐
js合并两个对象(面试题)
The no category parents plug-in helps you remove the category prefix from the category link
JS interview questions - arrow function, find and filter some and every
导师转我800块,让我仿真一个电路(电源设计)
如何养成一个好习惯?靠毅力?靠决心?都不是!
Use yolov3 to train yourself to make datasets and get started quickly
【Go】Gin源码解读
Introduction to database system - Chapter 2 - relational database (2.1~2.3) (important knowledge points)
What is the latest popular annuity insurance product with higher income in 202?
为WordPress相关日志插件增加自动缩略图功能
WordPress site link modification plug-in: Velvet Blues update URLs
Problems encountered when using nailing intranet to penetrate and upload PHP projects
Split data - horizontal split and vertical split
Test cos HTML cache static cache plug-in
Only when you find your own advantages can you work tirelessly and get twice the result with half the effort!
WordPress站内链接修改插件:Velvet Blues Update URLs
再不刷题就晚了,最全的BAT大厂面试题整理
让WordPress支持注册用户上传自定义头像功能
msf cs openssl流量加密
李飞飞:我更像物理学界的科学家,而不是工程师|深度学习崛起十年