【发布时间】:2017-10-20 22:39:47
【问题描述】:
我正在尝试将数组类型定义为基本上如下所示:
[
{
name: string,
comment: string
},
{
name: string,
comment: string
}
]
但无论数组中有多少个 cmets,它都需要工作。
我发现了一些像 How to define array type in typescript? 这样的人设置长度的例子
但我无法让它为我正在做的事情工作,这里是上下文:
class Post{
person: string;
bird: string;
content: string;
image: string;
comments: Array<MyType>;
score: number;
grade: number;
constructor(p: string, b: string, c: string, i: string = '', cm: Array<MyType> = []) {
this.person = p
this.bird = b
this.content = c
this.image = i
this.comments = cm
this.score = 0
this.grade = this.score + this.cm.length
}
}
我应该如何定义类型 MyType?
【问题讨论】:
标签: arrays class typescript types constructor