我正在学习打字稿,并且试图定义一个遍历对象值的函数,但是当我这样做时,tslint
告诉我:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. No index signature with a parameter of type 'string' was found on type '{}'.ts(7053)
这是我的代码:
function proxyData(data: object) {
Object.keys(data).forEach((key: string) => {
console.log(data[key]);
});
}
在打字稿对象中,默认情况下没有定义任何键。如果要访问已知结构上的键,请明确指定数据对象。
按定义定义对象,