I have a constant:
export const LIST_OF_TYPES = {
TYPE1: 'type1',
TYPE2: 'type2',
};
In the component, I define the type
as follows:
export type IExampleComponentType = 'type1' | 'type2';
interface IExampleComponentProps {
type: IExampleComponentType;
}
const ExampleComponent: React.FC<IExampleComponentProps> = ({
type,
}) => {
...
When I try to send a prop to a component like this:
<ExampleComponent type={LIST_OF_TYPES.TYPE1} />
i see an error for prop type
like this:
TS2322: Type 'string' is not assignable to type 'IExampleComponentType'.
The expected type comes from property 'type' which is declared here on type 'IntrinsicAttributes & IExampleComponentProps & { children?: ReactNode; }'
What's wrong? How can I fix this?