facebook / prop-types

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

[Feature Request] Add Identify (id) type #242

Closed sag1v closed 5 years ago

sag1v commented 5 years ago

Request:

Add PropType.identify. Behind the scenes it will be just a wrapper for PropTypes.oneOfType([PropTypes.number, PropTypes.string])

Motivation:

We often need a prop that describes some kind of ID. When building a generic module, we often expect our id's to be either a string or a number (thats when we don't know what shape of data we will receive business wise).

Obviously this can be done in "user-land": Id: PropTypes.oneOfType([PropTypes.number, PropTypes.string])

But this is tedious to write every time and easily missed.

We can abstract it with a custom PropType but we will need to teach other developers on our team (or in contribution guide on github) to use this custom type when dealing with id's.

If we had a built-in, out of the box identify type it would be less tedious and may reduce the need to teach it as its part of the library.

ljharb commented 5 years ago
sag1v commented 5 years ago

OK, makes sense. Thanks