I am new to typescript. I am trying to create a component in which we pass color name or code and if color exist in the component stylesheet then it will use that style else it will use new color code. Earlier I was using javascript so i didn't required props to define but how i am getting compiler error "componentStyles".
interface Props { color: string}export default function MyComponent({color, children}: Props){ const componentStyles = [ color && styles[color], color && !styles[color] && {backgroundColor: color} ] return <View style={componentStyles}> {children}</View>}interface Styles { primary: ViewStyle}const styles = StyleSheet.create<Styles>({ primary: {backgroundColor: 'red'}})
I can call component using or
How should i declare Props types for no error from compiler?