facebook/react — pull request #1294 by chenglou (2014-03-24 01:22:06+00:00)
Title: Revamp and fix PropTypes

This uses the return value (a warning string or nothing) to indicate
whether a prop passes validation or not. It used to be done through
calling `console.warn` as a side-effect, except this didn't work well
with and `oneOfType`, which calls each validator.

The solution was to insert a `.weak` prop to each validator to suppress
the warning message. This is overkill and also doesn't work well in
because it increases the potential API surface.

So .weak is no longer needed: fixes #863.

Backward compatibility for custom validators: since they didn't return
anything and directly call `console.warn` or something, this doesn't
break them.

Improvements:

- `arrayOf`, `oneOfType` and `oneOf` got better message now, since
they can get hold of their validator's message and output that
instead of a generic `warning: bla`.
- More complete tests, including testing custom types and `isRequired`
on everything.

Bug fixes:

- oneOfType(...).isRequired didn't work. The workaround was to
use `oneOfType(a.isRequired, b.isRequired, ...)`. This means
`oneOfType(a.isRequired, b)` doesn't make sense. The new
version simply makes `oneOfType(...).isRequired` possible.
- `oneOf([true])` worked for 'true' boolean because it
converted everything to string before comparing. It no
longer does.