Issue
I am a beginner at typescript and I am using it in reactjs but I am getting errors. 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.
export const colors = {
RootBackground: "#fff",
}
style = {
[
buttonStyle ? buttonStyle : styles.button,
{
backgroundColor: colors[color],
width
},
]
}
Note: Error is on this line colors[color]
Solution
Limit color to be a key of colors:
interface Props {
color: keyof typeof colors
// other props
}
Answered By - Ori Drori
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.