I need to differentiate between two fields in a schema:
enum Action = {
CREATE: 'create'
}
enum ObjectType = {
Potatoe: 'potatoe',
Tomatoe: 'tomatoe'
}
export const TestSchema = z.object({
action: z.nativeEnum(Action),
objectType: z.nativeEnum(ObjectType),
payload: // need to discriminate based on both `action` and `objectType` values,
});
In the provided simplified example, I am looking to categorize the type of the payload
depending on the values of both keys action
and objectType
.
discriminatedUnion
[ref] Seems to only allow discrimination by one field