Is there a built-in way to prevent ID duplicates using Zod?
Let's say that your data is an array of objects with "id" and "name" fields:
as you can see, the id is duplicated but it should be unique. Does Zod have a built-in method to validate against this kind of issue? I wasn't able to find any. Or am I forced to use .refine and create a new Set with all the ids in my data?
3 Replies
GitHub
Validate items uniqueness in
z.array
· colinhacks zod · Discussio...I was checking the docs to see if there was any way to validate if there was any duplicate items on an array, perhaps we could implement a unique() function that does just that for arrays? const sc...
yup I saw that discussion but no one mentions a built-in way to prevent duplicates, just workarounds that would be last resource for me
there are no built in ways to do that