-
-
Notifications
You must be signed in to change notification settings - Fork 205
Open
Description
Version Number
"react-hook-form": "^7.68.0", "@hookform/resolvers": "^5.2.2",
Codesandbox/Expo snack
https://codesandbox.io/p/sandbox/3fyn4r
Steps to reproduce
z.coerce.date() infers input as unknown and output as Date, causing TS error in react-hook-form:
Type 'unknown' is not assignable to type 'Date | null | undefined'
when i do this i get error bellow
const schema = z.object({
start_date: z.coerce.date().optional(),
});
useForm({
resolver: zodResolver(schema),
});
full error
Type 'Resolver<{ start_date?: unknown; }, any, { start_date?: Date | undefined; }>' is not assignable to type 'Resolver<{ start_date?: Date | undefined; }, any, { start_date?: Date | undefined; }>'.
Types of parameters 'options' and 'options' are incompatible.
Type 'ResolverOptions<{ start_date?: Date | undefined; }>' is not assignable to type 'ResolverOptions<{ start_date?: unknown; }>'.
Type '{ start_date?: unknown; }' is not assignable to type '{ start_date?: Date | undefined; }'.typescript(2322)
(property) resolver?: Resolver<{
start_date?: Date | undefined;
}, any, TFieldValues> | undefined
sample code
import { useForm } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
const schema = z.object({
start_date: z.coerce.date().optional(),
});
type FormData = z.infer<typeof schema>;
export default function App() {
useForm<FormData>({
resolver: zodResolver(schema),
});
return null;
}
Expected behaviour
zodResolver should not break Resolver typing when using z.coerce.
What browsers are you seeing the problem on?
No response
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
No labels