Zod array with valid values

How can I make a zod array with certain valid values. I know I could do this with refine, but generally try to avoid that if possible to get better types. Thanks!
Solution:
This seems to work 👍
z.array(z.union([z.literal("NY"), z.literal("FL")]))
z.array(z.union([z.literal("NY"), z.literal("FL")]))
...
Jump to solution
2 Replies
Solution
Liam
Liam2y ago
This seems to work 👍
z.array(z.union([z.literal("NY"), z.literal("FL")]))
z.array(z.union([z.literal("NY"), z.literal("FL")]))
Sybatron
Sybatron2y ago
just use z.array(z.enum(["NY","FL"]))
Want results from more Discord servers?
Add your server