Skip to content

Modify existing schema #887

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

You must be logged in to vote

It looks like you are wanting .pick/.omit

I hope this helps.

const userRegisterSchema = z.object( {
    email: z.string().email(),
    password: z.string().min( passwordMin ).max( passwordMax ),
    confirmPassword: z.string().optional().or( z.literal( '' ) ),
    name: z.string().min( nameMin ).max( nameMax ),
    username: z.string().min( usernameMin ).max( usernameMax ),
} ).refine( ( data ) => data.confirmPassword === data.password, {
    message: "Passwords don't match.",
    path: [ 'confirmPassword' ],
} )

const userRegisterSchemaOnlyEmailAndPassword = userRegisterSchema.innerType().pick( {
    email: true,
    password: true,
} )
type UserRegisterSchemaOnlyEmailAndPassword = z.infer

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nemanjam
Comment options

Answer selected by nemanjam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants