Open Hucxley opened 2 months ago
Temporarily use union
to implement it for the time being. discriminatedUnion
does not support ZodEffects
. #2441
But the larger issue then is that we have 2 different schema definitions that rely on which value is present in the timeRange field. If "YOY" => use yearOverYearTimeRange, if "Anchor" => use anchorEventTimeRange. In my application, changing to .union does remove the error, but then when I try to fill out the form now, I'm getting errors in the YOY rules while using an anchorEvent entry type. It appears to only be applying the rules from the yearOverYearTimeRange schema.
I think I'll go back to the buggy behavior I had before and see if I can tidy that up for now because I can't be throwing errors for the wrong type of form that users can't resolve.
I'm new to Zod, but I seem to be having an issue where something is breaking one of the schemas that I'm using for a discriminated union. The code below is causing an error in the final line (the error states that (type at position 1 of source isn't compatible with position 1 of target):
If I try to use this, then I get a red line under anchorEventTimeRange in the discriminated union. If I move the .superRefine from the anchorEventTimeRange definition to after the discriminated union definition (append it to the end of the final line), it will allow the union to form, but the validation errors aren't consistently firing the correct max value.
To give more info about what I'm doing, in the year over year case, the max value for minimumEligibleDays is 365. However, if it is an anchor event case, then max values of minimumEligibleDays is (30 * the lesser of anchorEvent.preDurationMonth or anchorEvent.postDurationMonth).
Any ideas about what is going wrong with this that causes the discriminated union objects to not be compatible? I've tried adding a .superRefine to both of objects for each case, but that causes the year over year case to have an error that it is missing a bunch of properties that are truncated, and if I add it to the anchor event case as shown above, then I get the error mentioned above.