How React PropTypes allow different types for one prop?

You can use oneOfType() method of PropTypes.

For example, the height property can be defined with either string or number type as below:

Component.PropTypes = {
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};

July 11, 2022
124