Type problems after update resolver to 1.3.0
See original GitHub issueAfter 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:
- Created 3 years ago
- Reactions:7
- Comments:29 (12 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am getting this error in 2.8.1 again. 2.8.0 is fine.
@mrlubos My solution to this problem was to the code below in my jest.config file
I don’t know if is right, but it worked