colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.09k stars 1.15k forks source link

Creating a large schema from a subset #3698

Closed svidskiy closed 2 weeks ago

svidskiy commented 1 month ago

Hello, how correct this approach is for creating a large schema from a subset?

export const createCampaignSchema = z.object({
    ...campaignSetupSchema.shape,
    ...campaignTargetingSchema.shape,
    ...budgetBiddingSchema.shape
});
sunnylost commented 2 weeks ago

I think this is ok, or you can use merge:

export const createCampaignSchema = campaignSetupSchema
  .merge(campaignTargetingSchema)
  .merge(budgetBiddingSchema)