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
Big fan of this library's simplicity and flexibility. One thing I have noted however, is that parse() under-reports errors in an array, for items with the same key. Given the following code:
I would expect three too_small errors to occur - on data[1].name, data[2].name and data[2].value. However, only two errors are reported:
[
{
"code": "too_small",
"minimum": 1,
"type": "string",
"inclusive": true,
"path": [
1,
"name"
],
"message": "Should be at least 1 characters"
},
{
"code": "too_small",
"minimum": 1,
"type": "string",
"inclusive": true,
"path": [
2,
"value"
],
"message": "Should be at least 1 characters"
}
]
Using Zod v 1.10.3.
I am not sure if this is a bug, or a feature - if it's the latter it isn't documented anywhere. It's clear from the above that data[2] is getting validated as value is being reported, but something is swallowing the error for its name.
My use-case btw is validating form data, and I have repeated rows of the same object shape, so having the error highlighted on every instance is the desired outcome.
If there is either a fix, or a workaround for this, that'd be very much appreciated. Thanks.
The text was updated successfully, but these errors were encountered:
As a follow-up, did a bit of dig through the source code and think it's related to this issue: #112 namely that the seen parameter being passed through is effectively caching the first item's name validation result, and returning that, so the second item's name never gets validated. Your comment on #112 that states you have a fix for this, any idea how that is coming along? Else I can supply a fix myself via PR.
Hey there,
Big fan of this library's simplicity and flexibility. One thing I have noted however, is that
parse()
under-reports errors in an array, for items with the same key. Given the following code:I would expect three
too_small
errors to occur - ondata[1].name
,data[2].name
anddata[2].value
. However, only two errors are reported:Using Zod v 1.10.3.
I am not sure if this is a bug, or a feature - if it's the latter it isn't documented anywhere. It's clear from the above that
data[2]
is getting validated asvalue
is being reported, but something is swallowing the error for itsname
.My use-case btw is validating form data, and I have repeated rows of the same object shape, so having the error highlighted on every instance is the desired outcome.
If there is either a fix, or a workaround for this, that'd be very much appreciated. Thanks.
The text was updated successfully, but these errors were encountered: