Example enum:
enum Day{
MONDAY = 1,
TUESDAY = 2,
...
}
how do I validate with Zod an array of these type of enums?
z.array(Day)
doesn't work
z.array(Day.MONDAY | Day.TUESDAY ...)
doesn't work
From docs: https://zod.dev/?id=native-enums
enum Fruits {
Apple,
Banana,
}
const FruitEnum = z.nativeEnum(Fruits);
type FruitEnum = z.infer<typeof FruitEnum>; // Fruits
FruitEnum.parse(Fruits.Apple); // passes
FruitEnum.parse(Fruits.Banana); // passes
FruitEnum.parse(0); // passes
FruitEnum.parse(1); // passes
FruitEnum.parse(3); // fails