Why is "path" an array? #2118
-
Why is "path" an array? At first I thought I could put ["newPassword", "repeatNewPassword"] and both fields would be triggered by react-hook-form - but no eg.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
const schema = z.object( {
foo: z.object( {
bar: z.object( {
baz: z.string(),
} )
} )
} ).deepPartial().transform( ( value, ctx ) => {
ctx.addIssue( {
code: z.ZodIssueCode.custom,
message: 'message',
path: [ 'foo', 'bar', 'baz' ],
} )
} )
const result = schema.safeParse( {} )
!result.success && console.log( result.error.issues )
// [ { code: 'custom', message: 'message', path: [ 'foo', 'bar', 'baz' ] } ] If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏 |
Beta Was this translation helpful? Give feedback.
-
That You're right that it probably could have just been a string, but I wanted to account for the possibility that someone may want to add an issue "deeply" in a nested form, for instance. I see how this could be confusing though. |
Beta Was this translation helpful? Give feedback.
path
is an array of path segments, each containing a key nested under the previous path segment.If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks frien…