Skip to content

issue: resolver parameter of useForm hook is wrong typed #735

Closed
@supersnager

Description

@supersnager

Version Number

7.51.1

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/react-hook-form-and-yup-ytml5y

Steps to reproduce

  1. Go to https://codesandbox.io/p/sandbox/react-hook-form-and-yup-ytml5y
  2. Scroll down to line 49
  3. See Typescript error on "resolver" property:
Type 'Resolver<{ name: string; }, any>' is not assignable to type 'Resolver<FormInput, any>'.
  Types of parameters 'values' and 'values' are incompatible.
    Type 'FormInput' is not assignable to type '{ name: string; }'.typescript(2322)

Explanation

First of all thank you guys for this awesome library!
I 'm migrating my project from Formik to RHF and it's a really good experience, but I have found a bug with typings.

What I want to achieve is that my FormInput type have some properties that can have a null value.
In empty form, I want to set for example select field (ReactSelect) to empty value.
The field is nullable, but user has to fill it to submit the form.
Therefore I want my onsubmit type (FormOutput) should be validated version of FormInput.

Hoverver when the example is correctly typed, the Typescript error appears.

This is because the expected type of the resolver property is Resolver<TFieldValues, TContext> (Resolver)
but yupResolver function returns Resolver<Yup.InferType<typeof schema> (Resolver) and these types doesn't match

Please also see the comments in the linked sandbox.

I'm not sure, but It seems to me that the fix should be something similar to this fix react-hook-form/react-hook-form@662f2c6

Expected behaviour

No errors

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions