Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Zod · Module

.pick

.pick derives a new Zod object schema containing only selected properties from an existing object schema. Provide a mask with the keys to retain set to true.

How it works

For a Zod object schema, .pick creates a new schema containing only the properties whose keys are enabled in the selection object. The resulting schema can then validate data and provide a narrowed inferred TypeScript shape.

Syntax

schema.pick(mask)

Parameters

NameTypeDescription
maskobject maskAn object-shaped key selection in which properties set to true are retained in the derived object schema.

Returns

A new Zod object schema containing the selected keys.

Key points

  • .pick mirrors TypeScript's Pick concept, letting you derive a smaller runtime-validation schema from an existing Zod object schema.
  • Use .pick when a derived schema should expose and validate only a selected subset of an object's properties.
  • Pass a selection object with a property set to true to retain that property in the new schema.
  • The operation starts from a Zod object schema; it is not a general method for arbitrary schema types.

Common mistakes

  • The selection object specifies which existing schema properties to retain; keys not selected are excluded from the resulting schema.

Example: Pick selected object keys

import { z } from "zod";

const Recipe = z.object({
  title: z.string(),
  description: z.string().optional(),
  ingredients: z.array(z.string()),
});

const TitleOnly = Recipe.pick({ title: true });

console.log(TitleOnly.parse({ title: "Pasta" }));

Creates an object schema that retains only the selected title property and validates matching input.

When to use it

Expose a subset of fields

Create a public response schema from a larger internal object while retaining only approved fields.

Validate partial payload shapes

Build a focused validation schema for a form or endpoint that needs only selected properties.

Derive typed contracts

Keep runtime validation and inferred TypeScript types aligned when deriving narrower object contracts.

Interview questions

QWhat does Zod's .pick method do?

.pick returns a modified object schema that keeps only the selected keys. It is analogous to TypeScript's built-in Pick utility type and can be used to derive a narrower validated shape.

Follow-up: How would you create the inverse shape? Use .omit to remove specified keys instead of listing the keys to retain.

QHow do you select one property from an object schema?

Call .pick with an object whose selected property values are true, such as Recipe.pick({ title: true }). The returned schema contains the selected property and retains its original validator.

Follow-up: How can the resulting TypeScript type be obtained? Infer it from the returned schema with z.infer<typeof TitleOnly>.

QWhen is .pick useful in schema design?

The method is available on Zod object schemas and is intended for selecting certain keys from an existing schema. The resulting schema validates the selected object shape rather than requiring the original schema's other properties.

Follow-up: What related operation preserves all keys except a chosen set? Use .omit with the keys to exclude.

  • .omit
  • z.object
  • z.infer

Source: Defining schemas | Zod. Checked 2026-10-15.