我试着把一个对象数组Map到另一个对象数组,就像这样。
//array declarations
originals!: Original[];
reviews!= Review[]; //some logic fills this array
//mapping logic below
this.originals = this.reviews.map(x => ({
a: x.a_1,
b: x.b_1
//if I don't set the remaining properties
//I am getting compiler errors so I am forced to do something like
//the following, I don't want to do this.
c: "",
d: "" //and so on ..
});
original
和review
对象具有以下属性。
Original {
a: string,
b: string,
c: string,
d: string,
e: string
}
Review {
a_1: string,
b_1: string
}
问题-如何避免填充对象Original
的所有剩余属性?
1条答案
按热度按时间0lvr5msh1#
听起来您只需要可选属性:
c
、d
和e
现在具有类型string | undefined
。