如何解决我以ES6为目标时,Typescript编译器缺少ECMAScript 5支持
这是我的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)];
解决方法
编辑实际上,真正的问题是我混淆了lib
和target
(感谢@ritaj)。直接的解决方案是这样做:
{
"compilerOptions": {
"lib": ["es6","dom"],"target": "es6",...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。