Public 构造函数中的剩余参数

Public rest parameters in constructor

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

class XYZ {
   constructor(public firstname: string, public lastname: string, ...public emails: Array<string>) {
    }
}

1.5.0版本如何做到这一点? 如果我这样定义 class,我会遇到几个错误:

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.

谢谢 马里奥

There is an oversight in the spec,但rest参数不能为public或private。以下是修复代码的方法:

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