Zod array of dates
Can someone help me validate that a variable is an array of exactly two dates and ideally in the future.
Here is what I've currently got.
However it allows an array of two nulls which isn't what I want.
7 Replies
So, it should be an array of exactly 2 dates?
If so, you can achieve it like this:
For some reason this doesn't flag when date is an array of two nulls.
Well that is very interesting and almost sounds like a bug..
You could workaround it by using the .refine
GitHub
GitHub - colinhacks/zod: TypeScript-first schema validation with st...
TypeScript-first schema validation with static type inference - GitHub - colinhacks/zod: TypeScript-first schema validation with static type inference
Also, I'm not 100% sure that's how you want it, but you could try something like this:
Cheers
let me know if it works