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
Describe the bug
This is regarding the Zodresolver. The type of getFieldState(..).error is incorrect when using a schema inside an array schema. It is currently typed as FieldError | undefined, but it should be typed as Merge<FieldError, (FieldError | undefined)[]> | undefined, just like formState.errors.<field> is.
At least, that is how the code behaves. I'm not sure if that new type will still fulfill the Resolver type, though.
To Reproduce
Steps to reproduce the behavior:
See the instructions in the codesandbox (copy pasted below):
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 behavior
I expect the type of getFieldState(..).error to be Merge<FieldError, (FieldError | undefined)[]> | undefined, instead of FieldError | undefined, which is the same as formState.errors.<field>.
Desktop (please complete the following information):
Describe the bug
This is regarding the Zodresolver. The type of
getFieldState(..).error
is incorrect when using a schema inside an array schema. It is currently typed asFieldError | undefined
, but it should be typed asMerge<FieldError, (FieldError | undefined)[]> | undefined
, just likeformState.errors.<field>
is.At least, that is how the code behaves. I'm not sure if that new type will still fulfill the
Resolver
type, though.To Reproduce
Steps to reproduce the behavior:
See the instructions in the codesandbox (copy pasted below):
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
Codesandbox link (Required)
Codesandbox link here
Expected behavior
I expect the type of
getFieldState(..).error
to beMerge<FieldError, (FieldError | undefined)[]> | undefined
, instead ofFieldError | undefined
, which is the same asformState.errors.<field>
.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: