Skip to content

Why is "path" an array? #2118

Answered by JacobWeisenburger
yepMad asked this question in Q&A
Discussion options

You must be logged in to vote

path is an array of path segments, each containing a key nested under the previous path segment.

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 frien…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@nimeshmaharjan1
Comment options

@peyronoscar
Comment options

@stevenprinsloo
Comment options

@stevenprinsloo
Comment options

Answer selected by JacobWeisenburger
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants