让我们看一下简单的代码:
let obj = {
a:1,
b:2,
c:3
}
for (let i in obj) {
console.log(obj[i]);
}
我们在obj[i]
上收到错误消息:
Element implicitly has an 'any' type because expression of type 'string'
can't be used to index type '{ a: number; b: number; c: number; }'.
No index signature with a parameter of type 'string' was found
on type '{ a: number; b: number; c: number; }'. ts(7053)
怎么了?