Validating array using zod
How is it supposed to be done?
It's returning errors that are basically flat arrays, I can't determine which element of the array is errorful
Any ideas? Help is GREATLY appreciated
6 Replies
z.array({})?
And then type the properties of the array elements
ok cool and all
say element 14th errored, how do I know that it's this element in particular that caused the error? (from frontend side)
Same thing applies to z.map, how do you know a particular key caused the error?
the only possible way I found so far is by parsing error.message into a json object, making it
any
(not typesafe 🤮)I would just iterate over the array and validate each one of them
I don't know if there's a way in zod to get the specific invalid element
that elimantes the point of having a .array thingy
idk if it's a zod issue, trpc issue, or tanstack-query issue
no cuz it validates the array in its entire and gives type inferrence
but it might be useful tho
fair enough
.path in zod actually references to where the error occured
no way in getting that from frontend unfortunately (as the path is just a string that refers to which trpc method was used)