[ts] typeof 'string' can not be used index type

typescript使用場景:用變量作爲object的key取值,語法報錯
typeof 'string'  can not be used index type
 
解決辦法
指定object的key的類型即可 obj: { [k:string]: string }
 
報錯代碼:
 
 
正常代碼:
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章