-
-
Notifications
You must be signed in to change notification settings - Fork 196
Open
Description
Summary
We get disagreements in typing for at least the following transform APIs:
.default()
(see below).coerce
(CodeSandbox).preprocess()
(CodeSandbox)
Version Number
5.2.0
Codesandbox/Expo snack
Steps to reproduce
Observe this code (also in Codesandbox ^):
import z from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm, UseFormRegister } from "react-hook-form";
const Foo = ({}) => {
const MySchema = z.strictObject({
numApples: z.number().nullable().default(null),
numBananas: z.number().nullable(), // (no prob here)
});
type MySchemaType = z.infer<typeof MySchema>;
const { register } = useForm({ resolver: zodResolver(MySchema) });
const register2: UseFormRegister<MySchemaType> = register; // Type error!
return <h1>Zod Form</h1>;
};
export default Foo;
Expected behaviour
No type errors.
But TS gives this error:
Type '{ numBananas: number | null; numApples?: number | null | undefined; }' is not assignable to type '{ numApples: number | null; numBananas: number | null; }'
I think z.infer
is getting numApples
type right (number | null
) while zodResolver
gets it wrong (number | null | undefined
).
I'm on latest versions of react-hook-form
, @hookform/resolvers
, and zod
.
Code of Conduct
- I agree to follow this project's Code of Conduct
Scrumplex, ShawnToubeau, gijsmin, hmaesta, fewhnhouse and 12 more
Metadata
Metadata
Assignees
Labels
No labels