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
SharpieMaster
SharpieMaster15mo ago
z.array({})? And then type the properties of the array elements
West side ⁉
West side ⁉OP15mo ago
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 🤮)
ArjunBroEpic
ArjunBroEpic15mo ago
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
West side ⁉
West side ⁉OP15mo ago
that elimantes the point of having a .array thingy idk if it's a zod issue, trpc issue, or tanstack-query issue
ArjunBroEpic
ArjunBroEpic15mo ago
no cuz it validates the array in its entire and gives type inferrence but it might be useful tho
West side ⁉
West side ⁉OP15mo ago
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)
Want results from more Discord servers?
Add your server