-
-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type 'ResolverOptions<FormValues>' is not assignable to type 'ResolverOptions<{..............}>' #574
Comments
Could you provide some more detail with a reproducible CSB? thanks |
I am facing the same issue |
added CSB |
You cast your https://codesandbox.io/s/react-hook-form-typescript-forked-34kq9w?file=/src/index.tsx |
Why, if I don't have to write schema for every form field? The form field cannot be undefined in my case |
Then your schema fields should be required: https://codesandbox.io/s/react-hook-form-typescript-forked-xj8fhw?file=/src/index.tsx |
Types are inferred from the Yup schema so remove |
const onSubmit = useCallback(
handleSubmit(async (data) => {
// Do your stuff
})
, []) react-hook-form is strongly typed, you can infer data types from |
Here is the updated release note, sorry for the mistake, it should be at least a minor version instead of a patch https://github.com/react-hook-form/resolvers/releases/tag/v3.1.1 |
@mtr1990 Can you provide a CodeSandbox with your issue? You probably don't need |
No longer gives error when removing
Just confirm function Thanks for your help :D |
Hi @jorisre, I think this is a different problem with types. When data depends on My case has 4 fields:
But I just want to validate for 2 fields The remaining 2 fields are You can check here: |
Then just add the fields without any validator: https://codesandbox.io/s/morning-glitter-ypdjnn?file=/src/logic.tsx |
Hi, Yes I know but is this a must?
if the case is createDate: and if the case is file: How will we define it? |
This is not really recommendable, but if that is, what you want, then do it like this: https://codesandbox.io/s/morning-glitter-ypdjnn?file=/src/logic.tsx |
@henrikvolmer Thank you so much, I will try it! |
Update:
=> Can catch errors. But type error
=> Can not catch errors. https://codesandbox.io/s/rough-bash-sj3f6x?file=/src/logic.tsx |
The solution that worked for me was that I forgot to add the shape of Yup schema. Ex. const schema = Yup.object<SomeInterface>().shape({
firstName: "first name here",
lastName: "last name here"
});
const { register, handleSubmit, formState: { errors }} = useForm({ resolver: yupResolver(schema) }); |
Describe the bug
TS2322: Type 'Resolver<{ ......... }, any>' is not assignable to type 'Resolver<FormValues, any>'. Types of parameters 'options' and 'options' are incompatible. Type 'ResolverOptions' is not assignable to type 'ResolverOptions<{ ......... }>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties. Type '{ ............. }' is not assignable to type 'FormValues'.
To Reproduce
Steps to reproduce the behavior:
CSB
https://codesandbox.io/s/react-hook-form-typescript-forked-3c7fy9?file=/src/index.tsx
The text was updated successfully, but these errors were encountered: