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

Zod · Function

z.intersection

Combines two Zod schemas with logical AND semantics. The input must satisfy both schemas, and the inferred type is their intersection.

How it works

z.intersection combines two schemas with logical AND semantics. Parsing succeeds only when the input satisfies both schemas, and the inferred TypeScript type is their intersection.

Syntax

z.intersection(a, b)

Parameters

NameTypeDescription
aZodTypeThe first schema to combine.
bZodTypeThe second schema to combine.

Returns

A ZodIntersection schema representing the logical intersection of the two input schemas.

Key points

  • The construct models TypeScript-style intersection semantics: both component schemas must hold.
  • Create an intersection by passing the two schemas directly to z.intersection.
  • Type inference reflects the shared result of the two input schemas.
  • Intersections can combine constraints from two object schemas.

Common mistakes

  • For object schemas, prefer extend instead of an intersection when possible.
  • The returned intersection schema does not provide common object helpers such as pick and omit.

Example: Intersect two schemas

import { z } from "zod";

const numeric = z.union([z.number(), z.string()]);
const booleanish = z.union([z.number(), z.boolean()]);
const both = z.intersection(numeric, booleanish);

console.log(both.parse(42)); // 42

The value must satisfy both schemas; here, only a number belongs to both unions.

When to use it

Compose logical AND validation

Combine independent validation constraints that an input must satisfy simultaneously.

Intersect object types

Require an object to conform to two object schemas at once.

Find overlapping union members

Derive the common accepted values of two union schemas.

Interview questions

QWhat does z.intersection do?

It creates a schema representing a logical AND of two schemas. An input must pass both schemas, and the inferred type is the intersection of their types.

Follow-up: What does intersecting two unions demonstrate? The result keeps values accepted by both unions; for numeric, string and numeric, boolean unions, that common set is number.

QWhat is the signature and an equivalent method form?

Use z.intersection(a, b) with two schemas as arguments. The resulting schema can then be used for normal parsing and type inference.

Follow-up: How can the same composition be expressed fluently? For supported schemas, use the .and() method on the first schema.

QWhen should object schemas use extend instead?

For combining object schemas, the documentation recommends A.extend(B) instead. It returns a ZodObject, while z.intersection(A, B) returns a ZodIntersection.

Follow-up: Why does the returned class matter? A ZodObject retains object-specific methods, whereas the intersection instance lacks helpers such as pick and omit.

  • z.union
  • ZodIntersection
  • .and()
  • z.object
  • z.extend

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