c1ub
c1ub
TTCTheo's Typesafe Cult
Created by c1ub on 5/24/2023 in #questions
Typescript wizards needed! Circular dependency with Zod inferred schema type withing superRefine()
I have a zod object and I have a superRefine() call on the object to do additional validation. I want to separate the function call from the function within superRefine() to another validation function that accepts (val, ctx) and performs the validations/adds issues there (see below example. It works functionality wise however the issue is when I use the z.infer type of the schema to provide the type of the val parameter I get a circular dependency error. How can I type this without creating a whole new duplicate type that doesn't use infer or using any?
5 replies
TTCTheo's Typesafe Cult
Created by c1ub on 5/20/2023 in #questions
Validation Errors. What’s the best approach?
Do you throw an exception? Do you return an object like ‘{ data: {}, errors: [] }’? How would you best handle this? It’s also a requirement that all the validation takes place to return a list of the items that are invalid. Any resources on this concept would be much appreciated too!
2 replies
TTCTheo's Typesafe Cult
Created by c1ub on 5/17/2023 in #questions
Is there a way in Zod to validate a field in a schema conditionally on another fields value?
i.e if z.object.itemType is set then z.object.itemMeta should not be null. Using refine it appears you don't have access to the object your inside of, so you can't check there and I don't want to refine on the whole object as I can only return one error message. Any thoughts or ideas?
4 replies