【发布时间】:2020-09-16 00:03:14
【问题描述】:
所以,我正在尝试为我的图标动态分配颜色...但是这行代码一直在抱怨,
let icon = iconsList[name];
当我悬停它时..这是解释“
元素隐式具有“any”类型,因为“string”类型的表达式不能用于索引类型“{ heart:string;星:字符串;比如:字符串;不喜欢:字符串;闪光:字符串;标记:字符串;过滤器:字符串;用户:字符串;圆圈:字符串;标签:字符串;日历:字符串;雪佛龙左:字符串;选项V:字符串;选项H:字符串;聊天:字符串;探索:字符串; }'。 在“{ heart: string; 类型”上找不到带有“string”类型参数的索引签名。星:字符串;比如:字符串;不喜欢:字符串;闪光:字符串;标记:字符串;过滤器:字符串;用户:字符串;圆圈:字符串;标签:字符串;日历:字符串;雪佛龙左:字符串;选项V:字符串;选项H:字符串;聊天:字符串;探索:字符串; }'.ts(7053)
interface Props{
name:string,
}
const Icon = ({ name }:Props) => {
const iconsList = {
heart: '',
star: '',
like: '',
dislike: '',
flash: '',
marker: '',
filter: '',
user: '',
circle: '',
hashtag: '',
calendar: '',
chevronLeft: '',
optionsV: '',
optionsH: '',
chat: '',
explore: ''
};
let icon = iconsList[name];
icon = icon.substr(3);
icon = String.fromCharCode(parseInt(icon, 16));
return icon;
};
export default Icon;
Vscode中代码的截图On line 25, am trying to pick the specific icon color but it complains
【问题讨论】:
-
你得到哪个错误代码?
-
元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型
标签: typescript react-native react-native-android