Approach for handling discriminatedUnion
with superRefine
#3830
Unanswered
crisfcodes
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dynamic Validation Schema
Base Schema: Create a base schema that contains common fields.
Dynamic Validations:
code
field.superRefine
in the base schema to maintain shared validation logic across all schemas.Code example
Problem
superRefine
it cannot be applied to the base schema if you plan to use schema methods like merge afterward. This limitation arises becausesuperRefine
returns aZod effect
, which prevents further modifications to the schema.so, how to apply common complex validations(
refine
orsuperRefine
) in the base schema but also running dynamic validations depending schema fields or external data?Aditional notes
I reviewed this question but I didn't see anything to use with this specific case
Beta Was this translation helpful? Give feedback.
All reactions