Skip to content

Partially execute a parse action #960

Answered by cefn
sschneider-ihre-pvs asked this question in Q&A
Discussion options

You must be logged in to vote

Have you considered the approach below, that allows you to base a new schema on picking any parts of an existing schema that you want...

import {z} from "zod";

const tightSchema = z.object({
  id:z.string(),
  rev:z.string(),
  message:z.string(),
})

const {shape} = tightSchema;

const looseSchema = z.object({
  message:shape.message,
  id: shape.id.optional(),
})

Replies: 3 comments

Comment options

You must be logged in to vote
0 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
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
3 participants
Converted from issue

This discussion was converted from issue #853 on February 23, 2022 13:26.