Closed ypresto closed 1 year ago
Hi, I have the same issue, and opened discussion here (still no replies) https://github.com/orgs/react-hook-form/discussions/10618
I think my problem is also related: https://github.com/orgs/react-hook-form/discussions/10660
Related to #575
asegarra suggestion fixed the issue https://github.com/react-hook-form/resolvers/issues/575#issuecomment-1693405121 for me too.
Adding NULL as a possible value for the input(select) in the FormInputType and specifying this type
resolver: yupResolver<FormInputs>(schema),
was accepted and now there are no type errors.
@ypresto null
is recognized as a value within the context, but the issue arises because your schema doesn't permit values that can be null. This discrepancy is the cause of the error you're encountering. In the most recent update, you have the option to provide your own schema or enable the resolver to deduce types automatically.
Describe the bug
Since v3.1.1, yupResolver() causes type mismatch between
required()
field and null value in defaultValues.Probably caused by this PR: https://github.com/react-hook-form/resolvers/pull/563
@hookform/resolvers: v3.1.1 react-hook-form: v7.45.1 yup: v1.2.0
To Reproduce
useForm({ defaultValues, resolver: yupResolver(validationSchema) })
.food
in codesandbox) to defaultValues (or justdefaultValues: { food: null }
).food
) asstring().required()
in validationSchema.useForm(...)
.One example of type error:
Codesandbox link (Required)
https://codesandbox.io/s/react-hook-form-yupresolver-null-type-error-with-tfieldvalues-cd3tcc?file=/src/App.tsx:842-873
(Note: template for yupResolver is too old as it uses v6 of react-hook-form.)
Expected behavior No type error found.
Note that react-select will set the value to null when it is cleared.