Let's say I have the following prop-type interface for an user object:
const userPropType = shape({
name: string,
address: string,
age: number
});
Then I wanted to validate a global users' object received by props, that is comprised of several individual user objects, which keys are random numeric IDs. For example:
{
3142: {
name: 'Jonh Doe',
address: 'Baker Street',
age: 23
},
4345: {
name: 'Jane Doe',
address: 'Fourth Avenue',
age: 64
}
}
I know I can validate the numeric keys without trouble using a Prop Type custom validator. But the issue would be: how can I validate my global users' object using a custom handler that could validate the keys dynamically, but also the values based on my already defined userPropType interface.
In this short example I could easily type check each of the user attributes on the custom validator, but if we consider a real case scenario where my user object could have more than 50 attributes, it would be pretty annoying to be custom validating each one of them, specially when I already have a defined propType for my single user object.
So, that's the question: is it possible to use an already defined prop-type interface inside a custom validator?
Thanks!