dillon1000/react

Commit

PropTypes: distinguish nullable from optional object field (#7291)

* PropTypes: distinguish nullable from optional object field

This gives a more precise message (no type semantics change) to the case of passing a field in an object, but whose value is `null`:

Before:

```js
propTypes: {
  foo: React.PropTypes.number.isRequired
}
```

Would scream "Required prop `foo` was not specified in `MyComp`".

Now it'll be "Required prop `foo` was specified in `MyComp`, but its value is `null`.".

Works as expected in nested objects.

This fixes the issue of a component transitively passing a `null`, specifying the correct field to the child but have the child tell it that it didn't provide the prop.

Optional field and nullable are two different things anyway.

* Add missing test case.

* Reword messages.
Browse files
Changed paths7 files
First-parent comparison
M src/addons/link/__tests__/ReactLinkPropTypes-test.js ModifiedM src/isomorphic/classic/__tests__/ReactContextValidator-test.js ModifiedM src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js ModifiedM src/isomorphic/classic/types/ReactPropTypes.js ModifiedM src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js ModifiedM src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js ModifiedM src/test/__tests__/ReactTestUtils-test.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…