Replies: 6 comments 2 replies
-
I can't speak to whether this is an actual bug, but one thing that has(as far as I know) always been an issue when using something like Thankfully export function useZodForm<Schema extends z.ZodTypeAny, Context = unknown>(
props: Exclude<UseFormProps<z.input<Schema>, Context>, "resolver"> & {
schema: Schema;
}
): UseFormReturn<z.input<Schema>, Context, z.infer<Schema>> {
return useForm<z.input<Schema>, Context, z.infer<Schema>>({
...props,
resolver: zodResolver(props.schema),
});
} Usage example: const MySchema = z.object({
numberField: z.string().pipe(z.coerce.number()),
});
export function Foo() {
const { handleSubmit } = useZodForm({
schema: MySchema,
defaultValues: {
// This is correctly typed as a string
numberField: "0",
},
});
return (
<form
onSubmit={handleSubmit((data) => {
// this is correctly typed as a number
console.log("submitted", data.numberField);
})}
></form>
);
} |
Beta Was this translation helpful? Give feedback.
-
I also encountered the same issue in my environment. In my case, the problem persists even in version In export type UseFormHandleSubmit<TFieldValues extends FieldValues, TTransformedValues extends FieldValues | undefined = undefined> = (onValid: TTransformedValues extends FieldValues ? SubmitHandler<TTransformedValues> : SubmitHandler<TFieldValues>, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<void>; In export type UseFormHandleSubmit<TFieldValues extends FieldValues> = (onValid: SubmitHandler<TFieldValues>, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<void>; |
Beta Was this translation helpful? Give feedback.
-
Oh man, this update just broke my app. This is a breaking change for a minor version update Cant pass my form around to other components |
Beta Was this translation helpful? Give feedback.
-
Same issue appeared for me after minor version upgrade to 7.45.1 breaking my build process. Using yup resolver. |
Beta Was this translation helpful? Give feedback.
-
Also using |
Beta Was this translation helpful? Give feedback.
-
I'm very sorry for reviving this conversation but I'm having the same issue after I went from My typescript version is |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Version Number
7.45.1
Codesandbox/Expo snack
N/A
Steps to reproduce
handleSubmit
types used to work on7.44.3
but after updating to7.45.1
is now undefined leading to a type error.For the following below example config the
data
property inhandleSubmit
used to be{ password: string}
but now isundefined extends FieldValues ? SubmitHandler<undefined> : SubmitHandler<{password: string}>
which leads to a type error'data' is possibly 'undefined'.
Maybe related? https://github.com/react-hook-form/react-hook-form/releases/tag/v7.44.0-next.0
Expected behaviour
Correct types
What browsers are you seeing the problem on?
No response
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions