我正在循环访问数组中的数据,并希望将我的循环项目投射到扩展接口(它有一个额外的标签字段)。我可以重铸什么?到“PersonLabel”?typecript cast/assertion with for循环
for (const person of people) {
person.label = `${person.namespace}:${person.name}`;
this.peopleList.push(person);
}
我试过的方法,如本(不编译):
for (const person:PersonLabel of people) {
person.label = `${person.namespace}:${person.name}`;
this.peopleList.push(person);
}
,这(不编译)
for (const person of people) {
person = typeof PersonLabel;
person.label = `${person.namespace}:${person.name}`;
this.peopleList.push(person);
}