facebook / prop-types

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

'bool' should read 'boolean' #337

Closed mikemaccana closed 3 years ago

mikemaccana commented 3 years ago

The JS Boolean primitive is called boolean rather than bool. Using the correct name fails.

Sorry of this sounds nitpicky but I just encountered this and it seems like a very odd choice. Changing it (and still allowing bool for compatibility purposes) might save someone else the surprise.

Is it possible to use function rather than func or is function being a keyword stopping this?

ljharb commented 3 years ago

It was intentional, because const { boolean } = PropTypes; was disallowed until ES6, and at the time React was created, both a great many supported browsers still lacked that support, and also transpilation was very rare.

The same is true for function.

At this point, they could certainly be changed, but that's either a breaking change for virtually zero value, or it's two aliases that this library has to maintain forever for also minimal value.

Given that this is a years-old pattern, and IDE autocompletions are quite familiar with the type signature of PropTypes, it seems like something that shouldn't pose a frequent surprise (altho you're not the only person surely; see #8, #185, etc).

mikemaccana commented 3 years ago

Fair enough. Could be worth a breaking change in future once ES5 support is dropped?

Also: Hi Jordan! 😃

ljharb commented 3 years ago

If React was interested in supporting propTypes in the future, that would be reasonable, but unfortunately it's far more likely that React will drop the feature entirely, in favor of suggesting people use TypeScript.