首页 > 其他 > 详细

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

时间:2020-12-25 19:38:12      阅读:37      评论:0      收藏:0      [点我收藏+]
typescript使用场景:用变量作为object的key取值,语法报错
typeof ‘string‘  can not be used index type
 
解决办法
指定object的key的类型即可 obj: { [k:string]: string }
 
报错代码:
技术分享图片
 
 
正常代码:
技术分享图片
 

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

原文:https://www.cnblogs.com/minnie-huang/p/14190077.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!