(TypeScript2)如何循环访问接口类型数组?

Ben*_*ald 4 typescript typescript2.0

在使用for循环时,let对象具有字符串类型,即使我迭代的对象是在接口中定义的类型.

以下是我正在使用的代码.当尝试访问在接口上定义的mapping.attribute作为字符串时,我得到错误[属性'属性'在类型'字符串'上不存在.

我有以下界面和功能:

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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如何定义for循环以便我可以使用在我的界面中定义的属性?

Bla*_*lux 14

我可以在更换时运行你的例子

for (let mapping in mappings) {
Run Code Online (Sandbox Code Playgroud)

for (let mapping of mappings) {
Run Code Online (Sandbox Code Playgroud)