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
I'm using the Zodresolver ("@hookform/resolvers": "^3.3.4") to do the validation. That might be related.
I've pasted the instructions from the Codesandbox page below. I added a regular string field ("nickname") to the demo as a control to demonstrate that non-array fields work correctly.
Instructions:
Notice how there are no errors starting out
Click "Submit"
Notice how form.getFieldState("files").error?.message is filled. That is because the error is on the array level of the schema (z.arr(..).min(1))
Click "Choose files" and add a file
Notice how form.getFieldState("files").error?.message is no longer filled. It's undefined (see console)
But notice now that form.getFieldState("files").error?.[0]?.message IS filled. Same goes for form.formState.errors.files?.[0]?.message
So getFieldState(..).error should share the signature of formState.errors.x, namely Merge<FieldError, (FieldError | undefined)[]> | undefined. However, it is typed only as FieldError | undefined
Check the code and look for the type error and my comment. You can verify the incorrect types there
Expected behaviour
I expect the type of getFieldState(..).error to be Merge<FieldError, (FieldError | undefined)[]> | undefined, instead of FieldError | undefined. formState.errors.<field>'s type is in fact Merge<FieldError, (FieldError | undefined)[]> | undefined, which I think is the correct type for both. That is because a field's error can be an array of FieldErrors or it could be a single FieldError, as shown in the demo (files and nickname fields, respectively).
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
Codesandbox/Expo snack
Codesandbox link here
Steps to reproduce
I'm using the Zodresolver ("@hookform/resolvers": "^3.3.4") to do the validation. That might be related.
I've pasted the instructions from the Codesandbox page below. I added a regular string field ("nickname") to the demo as a control to demonstrate that non-array fields work correctly.
Instructions:
Notice how there are no errors starting out
Click "Submit"
Notice how
form.getFieldState("files").error?.message
is filled. That is because the error is on the array level of the schema (z.arr(..).min(1)
)Click "Choose files" and add a file
Notice how
form.getFieldState("files").error?.message
is no longer filled. It's undefined (see console)But notice now that
form.getFieldState("files").error?.[0]?.message
IS filled. Same goes forform.formState.errors.files?.[0]?.message
So
getFieldState(..).error
should share the signature offormState.errors.x
, namelyMerge<FieldError, (FieldError | undefined)[]> | undefined
. However, it is typed only asFieldError | undefined
Check the code and look for the type error and my comment. You can verify the incorrect types there
Expected behaviour
I expect the type of
getFieldState(..).error
to beMerge<FieldError, (FieldError | undefined)[]> | undefined
, instead ofFieldError | undefined
.formState.errors.<field>
's type is in factMerge<FieldError, (FieldError | undefined)[]> | undefined
, which I think is the correct type for both. That is because a field's error can be an array ofFieldError
s or it could be a singleFieldError
, as shown in the demo (files
andnickname
fields, respectively).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: