Comments (23)
You can try this option:
...
} = useForm({
defaultValues: stripNulls(defaultValues) as DefaultValues<T>,
resolver: yupResolver(schema) as unknown as Resolver<T>,
mode: validateMode,
});
from resolvers.
If it worked before and now it doesn't, it's a problem with the library, not how we're using it.
from resolvers.
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
from resolvers.
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",
}
from resolvers.
i'm able to use @hookform/resolvers: 3.3.3
with yup: 0.32.11
but with any newer version of yup than that, it breaks. Just basing off of the quick start yup example https://www.npmjs.com/package/@hookform/resolvers#yup (but without using .shape(...)
. With it it does not work with these versions either.
edit: solved my issue #648 (comment)
from resolvers.
@greeeg
That post was posted by me with the same content.
from resolvers.
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 node_modules
and re-installed all my dependencies and what gave me errors before no longer does.
"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 generateSchema()
missing fields it is no longer doing so. I realise though that i did not share your original issue so if this is irrelevant please ignore.
from resolvers.
@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.
useForm<InferType<typeof schema>>()
from resolvers.
also facing this issue, has a fix been found?
from resolvers.
Can you provide a Codesandbox with the issue? thank you
from resolvers.
I have the same problem in version 3.0 plus. You can change the
export interface CreateFormOptions<T> { rules: Record<keyof T, yup.AnySchema>; defaultValues?: DefaultValues<T>; validateMode?: Mode; }
to
export interface CreateFormOptions<T> { rules: Record<keyof T, yup.AnySchema>; defaultValues: DefaultValues<T> | undefined; validateMode: Mode | undefined; }
It worked for me
from resolvers.
@jorisre @Hujianboo
thank you for your reply
The method you suggested didn't fix it.
from resolvers.
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
from resolvers.
@tjelvar-chromaway We would need your yarn.lock
or package-lock.json
file to see what exact versions you're using to explain why it works on your side.
On my side, in the CI with pinned versions, it does not work consistently
from resolvers.
@greeeg Got the same versions in the lock file
'@hookform/resolvers':
specifier: ^3.3.3
version: 3.3.3([email protected])
react-hook-form:
specifier: ^7.49.2
version: 7.49.2([email protected])
yup:
specifier: 1.3.3
version: 1.3.3
(deleted both node_modules
and my lock file and re-installed everything)
from resolvers.
I deleted node_modules and also deleted the lock file, but the error remained.
from resolvers.
I have the same problem, as soon as I use Fieldvalues
as parameter, typescript complains that the types of the schema doesn't match. This started at > 3.1.0, I'm also using yup.
from resolvers.
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.
from resolvers.
@brianbattenfeld
In this case, how can I use yup.InferType to solve the problem?
#648 (comment)
from resolvers.
Same problem here.
from resolvers.
Also facing this issue.
from resolvers.
Same here.
from resolvers.
Was able to fix it.
from
const validationSchema = Yup.object().shape({
email: Yup.string().email().required(errors.field),
password: Yup.string().required(errors.field).min(5),
});
to
const validationSchema = Yup.object({
email: Yup.string().email().required(errors.field),
password: Yup.string().required(errors.field).min(5),
});
from resolvers.
Related Issues (20)
- typescript problem in AJV resolver HOT 1
- Fields configured as mandatory are not being validated and are ignored.
- errors object creating circular structure with yup resolver
- Zod superRefine does not correctly revalidate the form on change HOT 2
- Issue with Resolvers tranform
- Extend typeboxResolver with additional types; getting "Unknown type" in Visit3
- AJV resolver is async mode is not working
- Support `@effect/schema` HOT 4
- when type of input is radio,valueAsNumber dont work anymore HOT 1
- `Joi` resolver crashes on `File` validation
- When using `classValidatorResolver`, combining `@IsOptional()` with `@Length()` makes the field required
- [Zod]: Resolver does not validate to reflect correct error state without manual form.trigger() HOT 8
- zodResolver / superRefine / useFieldArray: useForm errors are not updated to reflect zodResolver errors HOT 2
- Zodresolver `getFieldState(..).error` type is incorrect HOT 1
- Typeerror when used with zod 3.23 HOT 2
- Why Hookform resolver makes required fields optional?
- 3.6.0 breaks with the current release of valibot HOT 1
- Form submission proceeds with empty formValue when validation fails using check (formerly custom) in Valibot HOT 3
- weird error with valibot HOT 2
- Using `useFieldArray`, `shouldUseNativeValidation: true` and `joiResolver` together causes a bug
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resolvers.