I'm looping over data in an array and want to cast my looped item to an extended interface (it has an extra label field). What can I recast it? to a "PersonLabel"?
for (const person of people) {
person.label = `${person.namespace}:${person.name}`;
this.peopleList.push(person);
}
I tried approaches such as this (does not compile):
for (const person:PersonLabel of people) {
person.label = `${person.namespace}:${person.name}`;
this.peopleList.push(person);
}
and this (does not compile)
for (const person of people) {
person = typeof PersonLabel;
person.label = `${person.namespace}:${person.name}`;
this.peopleList.push(person);
}
You could try: