facebook / prop-types

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

Add new type checker "bothOfType" #252

Closed Poyoman39 closed 5 years ago

Poyoman39 commented 5 years ago

This is a feature request:

With proptypes, we already have "oneOfType" type checker, what about a "bothOfType" type checker ?

What is the use case: You have these proptypes: const vehicle = propTypes.shape({ engine: propTypes.string }) const car = propTypes.shape({ engine: propTypes.string, wheels: propTypes.number })

It would be fine to be able to write it like that: const car = propTypes.bothOfType([vehicle, propTypes.shape({ wheels: propTypes.number })])

In case vehicle and car have a lot of properties it allows doing type refactoring.

What do you think about it ?

ljharb commented 5 years ago

Note this already exists as and in https://npmjs.com/airbnb-prop-types (also note that shape always requires an object)

Poyoman39 commented 5 years ago

True enough ! :D Thank you for your answer ... i guess i should have googled it a bit more ...