Skip to content

Is there a way to deepPick, similar to deepPartial? #2083

Discussion options

You must be logged in to vote

Is this what you are looking for?

const person = z.object( {
    name: z.string(),
    school: z.object( {
        id: z.number(),
        name: z.string()
    } )
} )

const justSchoolName = person.shape.school.pick( {
    name: true
} )

console.log( justSchoolName.parse( { name: 'School of Rock' } ) )
// { name: 'School of Rock' }

If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏
https://github.com/sponsors/JacobWeisenburger

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by JacobWeisenburger
Comment options

You must be logged in to vote
2 replies
@MaheeGamage
Comment options

@DoubleDebug
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@DoubleDebug
Comment options

@timewarrior
Comment options

@timewarrior
Comment options

@thelinuxlich
Comment options

@bengry
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
8 participants
Converted from issue

This discussion was converted from issue #2072 on February 22, 2023 14:24.