Closed friedensstifter closed 1 year ago
Same here Error: Type 'Resolver<{ name: string | undefined; description: string | undefined; availableOnMobile: boolean | undefined; assign: boolean | undefined; recommend: boolean | undefined; duration: string | undefined; }>' is not assignable to type 'Resolver<{ name?: string | undefined; description?: string | undefined; availableOnMobile?: boolean | undefined; assign?: boolean | undefined; recommend?: boolean | undefined; duration?: string | undefined; }, any>'. Types of parameters 'values' and 'values' are incompatible. Type '{ name?: string | undefined; description?: string | undefined; availableOnMobile?: boolean | undefined; assign?: boolean | undefined; recommend?: boolean | undefined; duration?: string | undefined; }' is not assignable to type '{ name: string | undefined; description: string | undefined; availableOnMobile: boolean | undefined; assign: boolean | undefined; recommend: boolean | undefined; duration: string | undefined; }' Versions: yup: 1.2.0 @hookform/resolvers: 3.1.1 react-hook-form: 7.45.2
Reproduction: https://codesandbox.io/s/react-typescript-forked-vsszfm?file=/src/App.tsx
Same thing happens on zodResolver, created an issue #612
It does look like it was introduced by the change in 3.1.1, the reproduction in the original post can be made to work by following the instructions in the 3.1.1 release notes:
const schema = object({
title: string(),
news: string().required(),
});
type FormSchema = InferType<typeof schema>;
export default function NewsAdd() {
- const methods = useForm<FormSchema>({
+ const methods = useForm({
resolver: yupResolver(schema),
mode: "onChange",
reValidateMode: "onChange",
});
@Naddiseo is right. I'm closing.
Description: If a schema is defined with yup and a field is not marked as required, resolver show an error.
TS-Error:
Can't post codesandox-link. Codesandboy stays at v3.0.0. This works perfect. Only v3.1.1 got this problem.
Expected behavior I need to make fields optional. Set everything to required is a problem.