When using a for loop, my let object is of type string, although the object I am repeating is of the type defined in the interface.
Below is the code I'm using. When I try to access map.attribute, which is defined on the interface as a string, I get an error. [The attribute property does not exist in the string type.]
I have the following interface and function:
interface IMapping {
attribute: string;
property: string;
}
mapAttributes(mappings: IMapping[], values) {
for (let mapping in mappings) {
if (mapping.hasOwnProperty("attribute")) {
console.log(this.attributes.find(attribute => attribute.name === mapping.attribute).value);
}
}
}
How should a for loop be defined so that I can use the property that was defined in my interface?
source
share