构造函数中的公共rest参数

Mar*_*per 3 typescript typescript1.4

我看了一个使用版本1.0.0的打字稿教程.有一个类的示例,在构造函数中使用public rest参数:

class XYZ {
   constructor(public firstname: string, public lastname: string, ...public emails: Array<string>) {
    }
}
Run Code Online (Sandbox Code Playgroud)

如何在1.5.0版本中执行此操作?如果我像这样定义类,我有几个错误:

type.ts(14,75): error TS1005: '=' expected.
type.ts(14,81): error TS1005: ',' expected.
type.ts(14,88): error TS1005: '=' expected.
type.ts(14,96): error TS1109: Expression expected.
Run Code Online (Sandbox Code Playgroud)

谢谢马里奥

Pal*_*leo 6

规范中存在疏忽,但其余参数不能公开或私有.以下是修复代码的方法:

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