facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

Typo in `PropTypes.checkPropTypes` section of Docs #299

Closed marksmccann closed 4 years ago

marksmccann commented 4 years ago

I believe there is a small typo in the PropTypes.checkPropTypes section of your README.md. Not a big deal, but wanted to point it out. It tripped me up for a little bit and wanted save the next person some time :).

It reads:

PropTypes.checkPropTypes(myPropTypes, props, 'age', 'MyComponent');

When I believe it should read:

PropTypes.checkPropTypes(myPropTypes, props, 'prop', 'MyComponent');
ljharb commented 4 years ago

No, “age” is correct - it matches the code above it in the same section.

marksmccann commented 4 years ago

Fair enough, I am sure you no better than I, but are you sure? In the source, that argument is labeled as the location, it even gives the example of "prop" in the description.

/**
 * Assert that the values match with the type specs.
 * Error messages are memorized and will only be shown once.
 *
 * @param {object} typeSpecs Map of name to a ReactPropType
 * @param {object} values Runtime values that need to be type-checked
 * @param {string} location e.g. "prop", "context", "child context"
 * @param {string} componentName Name of the component for error messages.
 * @param {?Function} getStack Returns the component stack.
 * @private
 */
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
    ...
    var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' ...);

I believe, if you ran your example it would produce this:

Warning: Failed age type: Invalid age `age` of type `string` supplied to

instead of this:

Warning: Failed prop type: Invalid prop `age` of type `string` supplied to
ljharb commented 4 years ago

ahh, I see what you mean :-D and also why the mistake was made in #248 - which should be reverted.

marksmccann commented 4 years ago

I see you have a help wanted tag on the issue, if possible, I would love to make the update and create the PR for you.

ljharb commented 4 years ago

That’d be great; that’s indeed what the label means.