I am trying to do something like that:
interface Props extends RouteComponentProps {
country: 'ONE' | 'OTHER;
}
MyComponent.propTypes = {
country: PropTypes.oneOf(['ONE', 'OTHER']).isRequired,
};
And I am receiving this error:
Type 'Validator<string>' is not assignable to type 'Validator<"ONE" | "OTHER">'.
Type 'string' is not assignable to type '"ONE" | "OTHER"'.ts(2322)
Two doubts:
Narrow the type from string[] to ['ONE', 'OTHER'] using a const assertion:
MyComponent.propTypes = {
country: PropTypes.oneOf(['ONE', 'OTHER'] as const).isRequired,
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With