Skip to content
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

issue: the formState.errorsdefault type is incorrect #11841

Closed
1 task done
voinik opened this issue May 3, 2024 · 1 comment
Closed
1 task done

issue: the formState.errorsdefault type is incorrect #11841

voinik opened this issue May 3, 2024 · 1 comment

Comments

@voinik
Copy link

voinik commented May 3, 2024

Version Number

7.51.3 (latest)

Codesandbox/Expo snack

CodeSandbox link

Steps to reproduce

Check the source code of the CodeSandbox.

But summarized: When you use useFormContext() without passing it a generic, then the RHF types don't know what fields the form has.

When you extract formState.errors from the context, and try to access the errors for a field that is an array, you won't be able to index the error. So doing this gives you a type error:

const { formState } = useFormContext();
const e = formState.errors.files?.[0]?.message; // The types don't include a possible array type; no indexing allowed
console.log('e: ', e); // e: [{ message: '..' }] 

So e can be an array, as you can see in the log, but the default types don't think it can be.

Expected behaviour

I expect the default error types to expect the error to be an array (with inside it an object with a message property), as well as just an object with a message property.

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bluebill1049 bluebill1049 added the status: under investigation aware of this issue and pending for investigation label May 5, 2024
@bluebill1049
Copy link
Member

But summarized: When you use useFormContext() without passing it a generic, then the RHF types don't know what fields the form has.

Pretty sure that's the limitation.

@bluebill1049 bluebill1049 added design limitation and removed status: under investigation aware of this issue and pending for investigation labels May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants