While using a for loop my let object has the type of string, even though the object I am iterating through is of a type defined in an interface.
Below is the code I am using. When trying to access mapping.attribute which is defined on the interface as a string, I get the error [Property 'attribute' does not exist on type 'string'.]
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 the for loop be defined so that I can use a property that has been defined in my interface?