Element implicitly has an 'any' type because expression of type 'string' can't be used to index type
例子
let a={
b:"1",
c:"1"
}
var b="b";
let c=a[b]
let c=a[b]就会爆这个错误,因为在编译器看来b是一个未知的东西,它不属于a下面的任何一个属性b或者c,所以我们需要告诉它。
把代码改成下面:
let a={
b:"1",
c:"1"
}
var b="b";
let c=a[b as keyof typeof a]