Upgrading to 2.29.1 causing type errors with ZodDiscriminatedUnion
bug
I have a zod schema that uses a discriminated union, the zod adapter looks like its expecting it to be a object, i am not using it server side, just client side validation. I've tried wrapping the discriminated union in a object but no change to the errors.
Error:
> Argument of type 'ZodDiscriminatedUnion<"local", [ZodObject<{ eventId: ZodString; eventName: ZodString; ... 8 more ...; userName: ZodString; } & { ...; }, "strip", ZodTypeAny, { ...; }, { ...; }>, ZodObject<...>]>' is not assignable to parameter of type 'ZodObjectType'.
> Type 'string[]' is not assignable to type 'ZodFormattedError<unknown, string>'. Property '_errors' is missing in type 'string[]' but required in type '{ _errors: string[]; }'.
Code:
export const EventFormSchema = z.discriminatedUnion("local", [
BasicSchema,
ExtendedSchema
]);
//Errors are at EventFormSchema
const { form, errors, allErrors, validateForm, reset } = superForm(
defaults(zod(EventFormSchema)),
{
dataType: "json",
validators: zod(EventFormSchema)
}
);
The zod adapter type
> zod<ZodObjectType>(schema: ZodObjectType, options?: (AdapterOptions<Record<string, unknown>> & {
errorMap?: ZodErrorMap;
config?: Partial<Options>;
}) | undefined): ValidationAdapter<Record<string, unknown>, Record<string, unknown>>
The type of form is Record<string, unknown> and the type of errors is ValidationErrors<Record<string, unknown>> which is causing issues with my components and not being able to pass in the values.
0 条评论