-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
typescript type error for yupResolver #648
Comments
Can you provide a Codesandbox with the issue? thank you |
I have the same problem in version 3.0 plus. You can change the |
@jorisre @Hujianboo |
StackOverflow issue mentioning the same generic issue since upgrading: https://stackoverflow.com/questions/77593266/the-react-hook-forms-yup-resolver-is-upgraded-and-causes-a-type-error |
edit: solved my issue #648 (comment) |
@greeeg |
Okay now i'm gonna sound like generic tech support, but did you try shutting it off and turning it back on again? I removed my "dependencies": {
"react-hook-form": "^7.49.2",
"yup": "1.3.3",
"@hookform/resolvers": "^3.3.3",
...
} now i have import * as yup from "yup";
export const generateSchema = () =>
yup
.object({
obj: yup.object({
prop1: yup.string().required(),
prop2: yup.string().required(),
}),
})
.required(); and i'm able to use it like const methods = useForm({
resolver: yupResolver(generateSchema()),
}); Where ts was previously complaining about |
@tjelvar-chromaway We would need your On my side, in the CI with pinned versions, it does not work consistently |
@greeeg Got the same versions in the lock file
(deleted both |
I deleted node_modules and also deleted the lock file, but the error remained. |
I have the same problem, as soon as I use |
Similar issue here. Brand new to this so it didn't become broken after an upgrade but after downgrading to the versions mentioned by @yamatsum, this works as expected according to the docs. I was able to work around it for the time being by using yup.InferType, but this likely won't work for everyone's use cases and I'm not entirely sure yet how trustworthy these results will be. |
@brianbattenfeld |
@yamatsum something like the following, though you might need to do a little shuffling around since you're wrapping this all and using the generic.
|
If it worked before and now it doesn't, it's a problem with the library, not how we're using it. |
I think the issue start appearing after this commit: 918d72f, but IMHO the resolver is fine, but problem lies in RHF typings. I reported it here: react-hook-form/react-hook-form#11686 |
Same problem here. |
Also facing this issue. |
Same here. |
You can try this option: ...
} = useForm({
defaultValues: stripNulls(defaultValues) as DefaultValues<T>,
resolver: yupResolver(schema) as unknown as Resolver<T>,
mode: validateMode,
}); |
Was able to fix it. from
to
|
Still facing this issue as well. Node: v20.12.2 {
"yup": "^1.4.0",
"typescript": "~5.4.2",
"@hookform/resolvers": "^3.3.4",
"react-hook-form": "^7.51.3",
} |
also facing this issue, has a fix been found? |
I am getting error like this "Argument of type 'ObjectSchema<{ sourceName: string; ingestionFor: string; ingestionType: string; ingestAssetDetails: { key?: string | undefined; value?: string | undefined; fixedInterval?: string | undefined; addTo?: string | undefined; mrssURL: string; } | Maybe<...>; ... 9 more ...; epgFTPDetails: AnyPresentValue; }, AnyObject, { ...' is not assignable to parameter of type 'AnyObjectSchema | Lazy<any, unknown>'" "yup": "^1.0.0", |
The issue seems to be coming from the return type update made in #625 |
Nope, imo it started with 3.1.1 (https://github.com/react-hook-form/resolvers/releases/tag/v3.1.1), @yamatsum could you please try 3.1.0 to verify? The "after" excerpt of the release notes works fine with 3.1.0, but not with 3.1.1+ in my codebase, I've also seen similar problems in other issues starting with 3.1.1. |
I was able to solve this with the following:
By extending my interface with FieldValues, the error disappeared. |
Same issue here - pinning to 3.1.0 for now, as that works as before. The new behaviour seems to expect that the type inferred from the Yup schema is the same as the type passed to the |
Describe the bug
I upgraded the version from 2.9.10 to 3.3.2 and it stopped working.
To Reproduce
I am creating a generic function that wraps useForm
There was no problem with previous versions
A type error occurred at resolver after updating the version.
I tried making some changes based on the release notes, but it didn't work.
The text was updated successfully, but these errors were encountered: