构造一个类数组

时间:2018-10-05 09:33:57

标签: javascript typescript

我有一个类似下面的User类,可以正常工作。现在,我也想将他的Post[]构造为实际的Post类,但是我不知道该怎么做。

export class User {

    private _id: number;

    private _name: string;

    private _email: string;

    private _posts;  <--------------

    public constructor(data?: Partial<User>) {
        Object.assign(this, data);
    }

    Getters and setters

}

1 个答案:

答案 0 :(得分:0)

尝试

export class User {

  private _id: number;

  private _name: string;

  private _email: string;

  private _posts: Any[];

  public constructor(data?: Partial<User>) {
    Object.assign(this, data);
  }

  Getters and setters
}