resolvers: [Bug]: Document issue
Version Number
7.15.4
Codesandbox/Expo snack
https://codesandbox.io/s/sweet-dream-58m9v
Steps to reproduce
- Code was copied from the documentation.
- Run
tsc
- Or in VSCode in the line it shows the error.
Expected behaviour
Without any issue.
What browsers are you seeing the problem on?
No response
Relevant log output
Type error: Type '(values: unknown, context: object, options: ResolverOptions<AssertsShape<Assign<ObjectShape, { firstName: RequiredStringSchema<string, Record<string, any>>; age: RequiredNumberSchema<number, Record<...>>; }>>>) => Promise<...>' is not assignable to type 'Resolver<IFormInputs, object>'.
Types of parameters 'options' and 'options' are incompatible.
Type 'ResolverOptions<IFormInputs>' is not assignable to type 'ResolverOptions<AssertsShape<Assign<ObjectShape, { firstName: RequiredStringSchema<string, Record<string, any>>; age: RequiredNumberSchema<number, Record<string, any>>; }>>>'.
Type 'IFormInputs' is not assignable to type 'AssertsShape<Assign<ObjectShape, { firstName: RequiredStringSchema<string, Record<string, any>>; age: RequiredNumberSchema<number, Record<string, any>>; }>>'.
Index signature for type 'string' is missing in type 'IFormInputs'.
53 | formState: { errors },
54 | } = useForm<IFormInputs>({
> 55 | resolver: yupResolver(schema),
| ^
56 | });
57 | const onSubmit = (data: IFormInputs) => console.log(data);
58 |
error Command failed with exit code 1.
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 8
- Comments: 41 (22 by maintainers)
Commits related to this issue
- formularios validacao de formulario https://github.com/react-hook-form/resolvers/issues/245 — committed to marocss/gofinances by marocss 3 years ago
Having the same problem with version 3.1.1
PS: as a solution, I did downgrade to 2.9.10 which is working
@wroughtec adding the
.required()
fix the issue as well.follow the updated doc for now: https://react-hook-form.com/get-started#SchemaValidation @vtrphan
Last clarification. This used to pass:
While with 2.8.1 it will show an error showing that the schema is incompatible with the manually specified type.
Also, if you do:
It will also show an error since the schema is incompatible with the default values! 🎉
this issue forced me to change from yup to zod in my new project. the issue still exist in @hookform/resolvers@3.3.2
I had a similar issue. The fix was to make the array of string required, ie:
We will revert this feature for now, and make it a potential break change for v3. Thanks very much for your contribution by the way.
Hey Guys,
Sorry for the delay, the last version of resolvers (2.8.2) should fix that issue. If you have a different error, please open a new issue.
great think safer to go down that route then 😃
@bluebill1049 In this example, changing the schema to:
Works. Which actually fixes potential problems since not using
defined
orrequired
meansundefined
is a valid value, and it’s better to be explicit about this.Also now you don’t have to pass the type to useForm as it should be correctly inferred from the schema.
So using the following code is enough and will show problems with the schema.
It sure is stricter, but definitely safer!
Thanks @julienfouilhe no one’s fault here 😃 I do appreciate your contribution and help. we are all trying to make this works for everyone.
Take a look at this codesandobx: https://codesandbox.io/s/react-hook-form-validationschema-v7-ts-eb41q?file=/src/index.tsx the issue is probably more obvious, switching from 2.8.1 to 2.8.0