You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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();conste=formState.errors.files?.[0]?.message;// The types don't include a possible array type; no indexing allowedconsole.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
The text was updated successfully, but these errors were encountered:
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: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 amessage
property.What browsers are you seeing the problem on?
No response
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: