No warnings for invalid validators inside shape #220
Description
This could be related to #181
In a project we noticed that having typos in prop type definitions that are nested inside a PropTypes.shape
do not generate warnings in version 15.6.2
:
{
a: PropTypes.shape({
b: PropTypes.boolean // <- is undefined
})
}
I've boiled it down to these test cases:
Case 1:
const PropTypes = require('prop-types');
PropTypes.checkPropTypes({ a: undefined }, { a: "hello" });
Case 2:
const PropTypes = require('prop-types');
PropTypes.checkPropTypes(
{ a: PropTypes.shape({ b: undefined }) },
{ a: { b: "hello" } }
);
Case 1 generates a warning, as expected:
Warning: Failed undefined type: React class: undefined type `a` is invalid; it must be a function, usually from the `prop-types` package, but received `undefined`.
Case 2, however, does not output any error or warning 😞 In other words, it seems like if you use an invalid validator inside a PropTypes.shape
, validation will always pass and no compile time warning or error is visible, which means there might be potential for some sneaky runtime bugs.
I've tested this in many different versions (as low as 0.2.0
and 0.1.0
and it seems to be consistent across all versions.
Is this somehow the intended behaviour? If so, what is a good way to get compile-time errors/warnings for invalid validators used inside PropTypes.shape
?