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]