Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TypeScript-针对es2018时rest操作员行为不起作用_Typescript - Fatal编程技术网

TypeScript-针对es2018时rest操作员行为不起作用

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的以下错误 类型必须具有返回 迭代器 上面是什么 在本地

此代码在TypeScript中工作

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吗?