当前位置: 首页 > Web前端 > HTML

[React][TS]elementimplicitlyhasan'any'typebecause...告警解决方法

时间:2023-03-28 12:30:09 HTML

Sifutitlecannotexceed64validcharactersemm...完整的标题是《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创建,受ContentInfo类型限制。解决方法:对类型ContentInfo添加类型限制,添加[key:string]:string|