-
- Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
static propTypes = { unusedProp: PropTypes.object.isRequired, usedProp: PropTypes.func.isRequired, };
In this case, if I'm defining two props out of which I'm not using the first one inside component I'm getting:
'unusedProp' PropType is defined but prop is never used
which is correct. But if I define something in these lines:
static propTypes = { ...someMoreProps, unusedProp: PropTypes.object.isRequired, usedProp: PropTypes.func.isRequired, };
I'm not going to get the error and I should. I'm still not using 'unusedProp' anywhere inside component and I'm not getting the error now that I have defined spread operator.
If anyone is asking why do I have these 'someMoreProps' rest syntax that is really common with some modules like redux-form. This is HOC component that one uses to wrap it's own component to add form validation. Module exports large number of props that nobody likes to write every single time so you just import them from module and add inside your propTypes as spread operator:
import { reduxForm, propTypes } from 'redux-form'; static propTypes = { ....propTypes, unusedProp: PropTypes.object.isRequired, usedProp: PropTypes.func.isRequired, };
If I'm seeing this correctly, there shouldn't be an error that some prop is not defined as it may be inside rest operator, but it should still error out for those defined outside spread operator which are not used in the app which isn't happening in our case.