0

I know you can specify prop types in React, but can you specify only these prop types?

So in the code below name is a required prop. But can I make a warning show if you pass an additional prop eg 'age' without specifying a prop type for this field?

My thinking is to ensure that I have 100% coverage for my prop types.

import PropTypes from "prop-types";

const Component = () => {
  return (
   // stuff
  );
};

Choose.propTypes = {
  name: PropTypes.string.isRequired,
};
Evanss
  • 23,390
  • 94
  • 282
  • 505
  • I think this might help https://stackoverflow.com/questions/38684925/react-eslint-error-missing-in-props-validation – azium Oct 24 '18 at 05:19
  • 1
    flow validator has [strict object check](https://flow.org/en/docs/types/objects/#toc-exact-object-types) that can be applied to `props`. PropTypes cannot do that since you specify type per each key in `props`. There is no way to apply restriction on `props` as a whole. – skyboyer Nov 15 '18 at 20:15

0 Answers0