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?
4 Replies
c1ub
c1ubOP2y ago
an example here the val: SchemaType in the validationRules function here causes the circular dependency error ps: forgive me i dont type in serif font idk what happened
c1ub
c1ubOP2y ago
prakhar_goel
prakhar_goel2y ago
does this not work for your use case
function refineAgain(schema: ZodSchema<z.infer<typeof zodSchema>>) {
return schema.superRefine((data) => data);
}
function refineAgain(schema: ZodSchema<z.infer<typeof zodSchema>>) {
return schema.superRefine((data) => data);
}
Sybatron
Sybatron2y ago
these are the docs in zod for recursive types are you have one here
Want results from more Discord servers?
Add your server