I'm attempting to create a Yup validation schema for an object with the following structure:
interface myObject {
prop0: Date
prop1: {
nestedProp1: string
nestedProp2: number
[key: string]: string | number
}
}
This is what I have tried so far:
yup.object({
prop0: yup.string(),
prop1: yup.object({
nestedProp1: yup.string(),
nestedProp2: yup.number(),
// struggling with dynamic type validation here
})
})
I am having difficulty writing the correct validation for the dynamic key within prop1
.
Update: I am aiming to use this type as a generic for a function, and then extract its schema using SchemaOf in order to define another parameter in the function (where I input the schema).
Here's a sandbox link where I'm simulating the actual scenario.
You can see that TypeScript is showing an error on line 39.