question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

yupResolver raise Types of parameters 'options' and 'options' are incompatible at react-hook-form 7.15.0

See original GitHub issue

Hello.

Describe the bug

I updated react-hook-form 7.15.0, yupResolver raise following type error messages.

Type '<TFieldValues extends Record<string, any>, TContext>(values: UnpackNestedValue<TFieldValues>, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<...>' is not assignable to type 'Resolver<FormType, object>'.
  Types of parameters 'options' and 'options' are incompatible.

Same code with react-hook-form 7.14.2 works fine(no type error).

versions

  • react: 17.0.2
  • react-hook-form: 7.15.0
  • @hookform/resolvers: 2.8.0
  • dayjs: 1.10.6
  • yup: 0.32.9
  • typescript: 4.3.5

To Reproduce

  1. Go to https://codesandbox.io/s/sad-wilson-rvpvv?file=/src/App.tsx
  2. move mouse cursor to line 22 and hover resolver
  3. Error message popup.

Codesandbox link (Required)

https://codesandbox.io/s/sad-wilson-rvpvv?file=/src/App.tsx:456-464

Expected behavior

No type error raised, or I want to know how to avoid type error (react-hook-form 7.14.2 works fine)

Screenshots

スクリーンショット 2021-09-07 22 26 31

Desktop (please complete the following information):

  • OS: macOS
  • Browser Chrome
  • Version 92.0.4515.159(Official Build) (x86_64)

Additional context

None

Thank you!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:24 (9 by maintainers)

github_iconTop GitHub Comments

6reactions
Mihai-githubcommented, Sep 20, 2021

Hi, My current setup is:

@hookform/resolvers”: “^2.8.1”, “react-hook-form”: “7.15.4”, “yup”: “^0.32.9”, “@types/yup”: “^0.29.13”


They are the latest versions that are atm available and how I solved the above error is by using the yupResolver with the next generic type yupResolver<yup.AnyObjectSchema>. An example could be the following:


export type TModelRegisterFormInputs = {
    email: string;
    password: string;
    passwordConfirmation: string;
    role: Roles;
    callback?: any;
};

const schema = yup.object().shape({
    email: yup.string().required(),
    password: yup
        .string()
        .required()
        .min(4, 'Password is too short - should be 8 chars minimum.')
        .matches(/[a-zA-Z]/, 'Password can only contain Latin letters.'),
    passwordConfirmation: yup
        .string()
        .required()
        .oneOf([yup.ref('password'), null], 'Passwords must match'),
});

const {
        handleSubmit,
        formState: {errors},
        control,
    } = useForm<TModelRegisterFormInputs>({
        resolver: yupResolver<yup.AnyObjectSchema>(schema),
    });


You can also add the defaultValues and I would recommend you to do that.

Hope it helps you 😃

4reactions
bluebill1049commented, Sep 27, 2021

7.16.0 solve the original issue above. the other issue is related to 2.8.1 https://github.com/react-hook-form/resolvers/issues/245

Read more comments on GitHub >

github_iconTop Results From Across the Web

TS Support | React Hook Form - Simple React forms validation
Performant, flexible and extensible forms with easy-to-use validation.
Read more >
signature for type 'string' is missing error when assigning Yup ...
I'm using material ui with react-hook-form and yup to create and ... n Types of parameters 'options' and 'options' are incompatible.
Read more >
react-hook-form | Yarn - Package Manager
Performant, flexible and extensible forms library for React Hooks. react, hooks, form ... React Hook Form Logo - React hook custom hook for...
Read more >
React Hook Form - Reset form with default values and clear ...
The solution is to use the reset() function from the React Hook Form library, if you execute the function without any parameters (...
Read more >
API Documentation - Simple React forms validation
useForm also has optional arguments. The following example demonstrates all options' default value. const { register } = useForm ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found