TypeScript-针对es2018时rest操作员行为不起作用
此代码在TypeScript中工作TypeScript-针对es2018时rest操作员行为不起作用,typescript,Typescript,此代码在TypeScript中工作 class Foo { constructor(...args: any[]) { } static make(...args: any[]): Foo { return new Foo(...args); } } …但在Visual Studio的TypeScript项目中,它不起作用。我在语句returnnewfoo(…args)中得到了args的以下错误 类型必须具有返回 迭代器 上面是什么 在本地
class Foo {
constructor(...args: any[]) {
}
static make(...args: any[]): Foo {
return new Foo(...args);
}
}
…但在Visual Studio的TypeScript项目中,它不起作用。我在语句returnnewfoo(…args)中得到了args
的以下错误代码>
类型必须具有返回
迭代器
上面是什么
在本地计算机上运行TypeScript 2.7。当我将构建目标更改为es2018时会出现问题。这似乎是编译器中的一个错误es2018
的默认库不正确。从编写时的编译器代码:
export function getDefaultLibFileName(options: CompilerOptions): string {
switch (options.target) {
case ScriptTarget.ESNext:
return "lib.esnext.full.d.ts";
case ScriptTarget.ES2017:
return "lib.es2017.full.d.ts";
case ScriptTarget.ES2016:
return "lib.es2016.full.d.ts";
case ScriptTarget.ES2015:
return "lib.es6.d.ts"; // We don't use lib.es2015.full.d.ts due to breaking change.
default:
return "lib.d.ts";
}
}
缺少es2018的选项。您可以手动指定适当的库:
{
"compilerOptions": {
"target": "es2018",
"lib": [
"es2018",
"dom"
]
}
}
您的浏览器支持es2018吗?