Skip to content
Discussion options

You must be logged in to vote

oof, the rabbit hole just keeps getting deeper.

After looking into it more, making deepRemoveDefaults wasn't too complicated. So it could be a cool idea for Zod to add, but until they do, here is a function that should work. I haven't done a ton of testing on this, so you may need to make a few tweeks. I just copied deepPartialify and made a few changes. Hope this solves your problem.

function deepRemoveDefaults ( schema: z.ZodTypeAny ): any {
    if ( schema instanceof z.ZodDefault )
        return deepRemoveDefaults( schema.removeDefault() )

    if ( schema instanceof z.ZodObject ) {
        const newShape: any = {}

        for ( const key in schema.shape ) {
            const fieldSc…

Replies: 3 comments 10 replies

Comment options

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

@JacobWeisenburger
Comment options

@dermotduffy
Comment options

@JacobWeisenburger
Comment options

@dermotduffy
Comment options

Comment options

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

@kylesuss
Comment options

@flroux
Comment options

@hi94740
Comment options

@sosweetham
Comment options

Answer selected by dermotduffy
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
8 participants