【发布时间】:2018-02-14 23:04:38
【问题描述】:
我正在循环遍历数组中的数据,并希望将循环项转换为扩展接口(它有一个额外的标签字段)。我可以重铸什么?到“PersonLabel”?
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);
}
【问题讨论】:
标签: typescript casting type-assertion