[React][TS] element implicitly has an 'any' type because...告警解决
文章目录
思否标题不能超过 64 个有效字符 emm...
完整标题是
《
React element implicitly has an 'any' type because expression of type 'string' can't be used to index type 告警解决
》
目前我遇到两种情况会出现这个告警
情景一:
keyToNameMap[keyItem]

解决办法:
给keyToNameMap的key和value加上类型限制,如下图
加上 { [key: string]: string } 
情景二:
同样的keyToNameMap[keyItem]
但这里的map (contentInfo)不是定义的常量。contentInfo由useState创建,受type ContentInfo限制。

解决办法:
给type ContentInfo加上类型限制,如下图
加上 [key: string]: string | number;
完结
同步更新到自己的语雀
https://www.yuque.com/diracke...

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论