[英]React typescript error: Element implicitly has an 'any' type
I am a beginner at typescript and I am using it in reactjs but I am getting errors.我是 typescript 的初学者,我在 reactjs 中使用它,但我遇到了错误。 Could someone please help me with how to resolve this issue?
有人可以帮我解决这个问题吗?
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type
. Element implicitly has an 'any' type because expression of type 'string' can't be used to index type
。
export const colors = {
RootBackground: "#fff",
}
style = {
[
buttonStyle ? buttonStyle : styles.button,
{
backgroundColor: colors[color],
width
},
]
}
Note: Error is on this line colors[color]
注意:错误是在这条线上
colors[color]
Limit color
to be a key of colors:限制
color
为 colors 的键:
interface Props {
color: keyof typeof colors
// other props
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.