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.

Type problems after update resolver to 1.3.0

See original GitHub issue

After update @hookform/resolvers to the version 1.3.0, this code above no longer works.

The TS compiler points out the error:

Type 'Resolver<AssertsShape<Assign<Record<string, AnySchema<any, any, any> | Reference<unknown> | Lazy<any, any>>, { title: RequiredStringSchema<string, Record<string, any>>; buttonTitle: RequiredStringSchema<...>; exibitionMode: RequiredStringSchema<...>; link: RequiredStringSchema<...>; duration: NumberSchema<...>; }>>,...' is not assignable to type 'Resolver<FormData, object>'.
  Types of parameters 'values' and 'values' are incompatible.
    Type 'FormData' is not assignable to type '{ [x: string]: never; title: string; buttonTitle: string; exibitionMode: string; link: string; duration: number; }'.
      Index signature is missing in type 'FormData'.ts(2322)
form.d.ts(39, 5): The expected type comes from property 'resolver' which is declared here on type 'Partial<{ mode: "onBlur" | "onChange" | "onSubmit" | "onTouched"

If I comment the lines of exibitionMode and colorBackground the error disappears.

This is the code that I’m working with

import { useForm } from 'react-hook-form'
import { yupResolver } from '@hookform/resolvers/yup'
import { object, string, number } from 'yup'

enum Color {
  DARK = 'dark',
  LIGHT = 'light',
  PURPLE = 'purple',
  ORANGE = 'orange',
  RED = 'red',
  GREEN = 'green'
}

enum ExibitionMode {
  INFINITY = 'infinity',
  LIMITED = 'limited'
}

interface FormData {
  title: string,
  buttonTitle: string,
  exibitionMode: ExibitionMode,
  link: string,
  duration: number,
  colorBackground: Color
}

const TITLE_MAX_LENGTH = 96
const BUTTON_TITLE_MAX_LENGTH = 28

const schema = object().shape({
  title: string().max(TITLE_MAX_LENGTH).required(),
  buttonTitle: string().max(BUTTON_TITLE_MAX_LENGTH).required(),
  exibitionMode: string().required(),
  link: string().required().url(),
  duration: number().when('exibitionMode', (exibitionMode, schema) => {
    return exibitionMode === ExibitionMode.LIMITED ? schema.min(1).required() : schema
  })
})

const Test = () => {
  const { register, handleSubmit } = useForm<FormData>({
    resolver: yupResolver(schema),
    mode: 'onBlur'
  })
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:29 (12 by maintainers)

github_iconTop GitHub Comments

27reactions
rstcruzocommented, Sep 21, 2021

I am getting this error in 2.8.1 again. 2.8.0 is fine.

5reactions
william-hotmartcommented, Jan 5, 2021

@mrlubos My solution to this problem was to the code below in my jest.config file

 "transformIgnorePatterns": [
    '/node_modules/(?!@hookform/*).+\\.[t|j]sx?$'
  ],

I don’t know if is right, but it worked

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compose Foundation - Android Developers
Write Jetpack Compose applications with ready to use building blocks and extend foundation to build your own design system pieces.
Read more >
SciPy 1.3.0 Release Notes — SciPy v1.9.3 Manual
SciPy 1.3.0 is the culmination of 5 months of hard work. It contains many new features, numerous bug-fixes, improved test coverage and better...
Read more >
Upgrading your build from Gradle 5.x to 6.0
When Gradle detects problems with task definitions (such as incorrectly defined inputs or outputs) it will show the following message on the console:....
Read more >
Changelog | Meteor API Docs
Update dependencies to avoid issues with Browserslist and caniuse-lite . PR. standard-minifier-js@2.8.1 : Update dependencies to avoid issues with Browserslist ...
Read more >
Change: the logging - Nginx.org
Bugfix: OCSP stapling might not work if the "resolver" directive was not ... Bugfix: nginx did not write anything to log and returned...
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