[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 }
報錯代碼:
正常代碼:
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
微服務實踐Aspire項目發佈到遠程k8s集羣
hiningrise
2024-06-02 14:24:56
微服務實踐之使用 Visual Studio 2022 調試Dapr 應用程序
hiningrise
2024-06-02 14:24:56
.NET開源、跨平臺、使用簡單的面部識別庫
追逐時光
2024-06-02 14:21:55
Python 潮流週刊#53:我輩楷模,一個約見諾獎得主,一個成爲核心開發者
豌豆花下貓
2024-06-02 14:19:15
Terraform管理OpenStack
馬昌偉
2024-06-02 14:13:44
matlab練習程序(LQR路徑跟蹤)
Dsp Tian
2024-06-02 14:11:04
h32 Most commonly used tags in HTML
emanlee
2024-06-02 14:10:23
css45 CSS Math Functions
emanlee
2024-06-02 14:10:23
CSS tutorials (w3school)
emanlee
2024-06-02 14:10:23
css44 CSS The !important Rule
emanlee
2024-06-02 14:10:23
css41 CSS Website Layout
emanlee
2024-06-02 14:10:23
css39 CSS Forms
emanlee
2024-06-02 14:10:23
css40 CSS Counters
emanlee
2024-06-02 14:10:23
css43 CSS Specificity
emanlee
2024-06-02 14:10:23
24小時熱門文章