diff --git a/lib/util/propTypes.js b/lib/util/propTypes.js index 6def79afc5..e816807127 100644 --- a/lib/util/propTypes.js +++ b/lib/util/propTypes.js @@ -422,13 +422,14 @@ module.exports = function propTypesInstructions(context, components, utils) { const callName = value.callee.property.name; const argument = value.arguments[0]; switch (callName) { - case 'shape': { + case 'shape': + case 'exact': { if (argument.type !== 'ObjectExpression') { // Invalid proptype or cannot analyse statically return {}; } const shapeTypeDefinition = { - type: 'shape', + type: callName, children: {} }; iterateProperties(context, argument.properties, (childKey, childValue, propNode) => { diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index f4dbde1519..17a9bf0d1c 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -5827,6 +5827,27 @@ ruleTester.run('prop-types', rule, { errors: [{ message: '\'dateCreated\' is missing in props validation' }] + }, + { + code: ` + function Zoo(props) { + return ( + <> + {props.foo.c} + + ); + } + + Zoo.propTypes = { + foo: PropTypes.exact({ + a: PropTypes.number, + b: PropTypes.number, + }), + }; + `, + errors: [{ + message: "'foo.c' is missing in props validation" + }] } ]) )