Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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 构造函数中的公共rest参数_Typescript_Typescript1.4 - Fatal编程技术网

Typescript 构造函数中的公共rest参数

Typescript 构造函数中的公共rest参数,typescript,typescript1.4,Typescript,Typescript1.4,我看了一个typescript教程,它使用1.0.0版。 有一个类的示例,在构造函数中使用公共rest参数: class XYZ { constructor(public firstname: string, public lastname: string, ...public emails: Array<string>) { } } 谢谢 Mario,但rest参数不能是public或private。下面是修复代码的方法: class XYZ { publi

我看了一个typescript教程,它使用1.0.0版。 有一个类的示例,在构造函数中使用公共rest参数:

class XYZ {
   constructor(public firstname: string, public lastname: string, ...public emails: Array<string>) {
    }
}
谢谢 Mario,但rest参数不能是public或private。下面是修复代码的方法:

class XYZ {
    public emails: string[];
    constructor(public firstName: string, public lastName: string, ...emails: string[]) {
        this.emails = emails;
    }
}

它应该是
公共电子邮件:string[]
,以避免成员获得
任何
类型。
class XYZ {
    public emails: string[];
    constructor(public firstName: string, public lastName: string, ...emails: string[]) {
        this.emails = emails;
    }
}