【发布时间】:2020-09-30 10:20:50
【问题描述】:
这是我的 tsconfig.json 文件:(它正在读取,因为之前缺少“异步”的错误已通过添加它来解决)
{
"compilerOptions": {
"lib": [ "es6","dom" ]
}
}
但我收到如下错误:
src\main.ts(85,20): error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.
src\main.ts(88,38): error TS2569: Type '""' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
扩展运算符或在字符串上使用 for..in 都不起作用:
var alphas:string[];
const text = "cABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (const char of text) {
alphas.push(char);
}
const availableGlyphs:string[] = [...'cABCDEFGHIJKLMNOPQRSTUVWXYZ'];
const glyph = availableGlyphs[Math.floor(Math.random()*availableGlyphs.length)];
【问题讨论】:
-
请同时添加引发错误的代码
-
目标是什么?
-
@Amir-Mousavi 你错过了吗?在标题 'targeting ES6' 和文本中它说 "lib": [ "es6","dom" ]
-
通过添加
es6库,您的代码不会编译为 es6。 -
lib与target不同。这是两个独立的配置选项
标签: typescript ecmascript-6 tsc