我正在循環訪問數組中的數據,並希望將我的循環項目投射到擴展接口(它有一個額外的標籤字段)。我可以重鑄什麼?到「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);
}