React typescript error: Element implicitly has an 'any' type
React typescript error: Element implicitly has an 'any' type
我是 typescript 的初学者,我在 reactjs 中使用它,但我遇到了错误。有人可以帮我解决这个问题吗? 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
},
]
}
注:错误在这一行colors[color]
限制color
为颜色键:
interface Props {
color: keyof typeof colors
// other props
}
我是 typescript 的初学者,我在 reactjs 中使用它,但我遇到了错误。有人可以帮我解决这个问题吗? 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
},
]
}
注:错误在这一行colors[color]
限制color
为颜色键:
interface Props {
color: keyof typeof colors
// other props
}