Input payloads
Create a request schema without server-managed identifiers or metadata.
Zod · Module
.omit() derives a Zod object schema without selected keys. Pass a mask with the keys to remove set to true.
.omit() creates a new object schema by removing the keys marked true in its mask. The resulting schema validates the remaining fields and infers a corresponding TypeScript object type, making it useful for derived shapes such as public or update payloads.
objectSchema.omit(mask)| Name | Type | Description |
|---|---|---|
mask | object mask | An object mask whose properties set to true identify the keys to remove. |
A new Zod object schema with the masked keys omitted.
.omit() on an object schema to remove selected properties.true.Pick and Omit utility types..omit().import { z } from "zod";
const Recipe = z.object({
id: z.string(),
name: z.string(),
ingredients: z.array(z.string()),
});
const RecipeNoId = Recipe.omit({ id: true });
console.log(RecipeNoId.parse({
name: "Pasta",
ingredients: ["pasta", "tomatoes"],
}));Creates a recipe schema variant that validates and returns only the name and ingredients fields.
Create a request schema without server-managed identifiers or metadata.
Build a public-facing shape that excludes private object properties.
Reuse a base schema while defining update or create variants with different fields.
.omit() method do, and how is it called?.omit() is an object-schema method that returns a modified schema with selected keys removed. Pass an object mask whose selected properties are set to true, such as Recipe.omit({ id: true }).
Follow-up: How would you derive a schema that retains only a chosen subset? Use .pick() with a mask of the keys to keep instead of .omit().
The result is a new object schema whose inferred type excludes the omitted properties. For example, omitting id from a recipe leaves a type containing name and ingredients.
Follow-up: What TypeScript utility type is this API conceptually related to? It parallels TypeScript's built-in Omit utility type.
.omit() useful in application schema design?Use .omit() when a base object schema contains fields that should not appear in a derived shape, such as removing an identifier from a create or transport payload. The method lets the derived schema reuse the remaining field definitions.
Follow-up: What alternative is appropriate when the derived shape should be assembled from unrelated fields? Define a separate z.object() schema or compose schemas with the object APIs documented by Zod.
z.object()z.pick()z.inferz.partial()z.extend()