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

Zod · Type Alias

output

z.output<typeof schema> extracts the TypeScript type produced by a Zod schema. It is especially useful when parsing transforms the input into a different output type.

How it works

z.output<T> is a type-level utility that extracts the inferred output type from a Zod schema. It matters when a schema transforms or otherwise maps its input into a different parsed value, so the output type can differ from the input type.

Syntax

z.output<typeof schema>

Parameters

NameTypeDescription
TZod schema typeA Zod schema type whose inferred parsed result should be extracted.

Returns

The schema's inferred output TypeScript type.

Key points

  • Zod provides type-level utilities for deriving static TypeScript types from schemas.
  • z.output<typeof schema> is equivalent to z.infer<typeof schema>.
  • Use z.input<typeof schema> when you need the schema's inferred input type.
  • Transforms are a common reason for input and output types to differ.

Common mistakes

  • For transforms and similar schemas, do not assume the input and output types are identical; use z.input and z.output independently.

Example: Extract a schema's output type

import { z } from "zod";

const schema = z.string().transform((value) => value.length);
type Result = z.output<typeof schema>;

const result: Result = schema.parse("Zod");
console.log(result); // 3

z.output<typeof schema> extracts the TypeScript type produced by parsing the schema.

When to use it

Model transformed values

A schema transforms a string into a number, and application code needs the resulting numeric type.

Separate input and output contracts

An API boundary needs separate static types for raw input and validated output.

Make parsed-result intent explicit

A codebase wants type declarations that clearly describe parsed results.

Interview questions

QWhat does z.output do?

z.output<typeof schema> extracts the schema's inferred output type at compile time. For an ordinary schema such as z.string(), that type is string; for a transforming schema, it is the transformed result.

Follow-up: How would you obtain the corresponding input type? Use z.input<typeof schema>, which can differ from the output type when the schema transforms values.

QWhen can a schema's output type differ from its input type?

A transform can make the schema accept one type and produce another. For example, a string-to-number transform has string as its input type and number as its output type, so z.output captures number.

Follow-up: Why is this distinction useful? It lets APIs type raw data and parsed data separately instead of incorrectly treating them as the same type.

QHow does z.output relate to z.infer?

z.infer<typeof schema> is equivalent to z.output<typeof schema> and returns the schema's output type. z.output is often clearer when the code is discussing the result produced by parsing.

Follow-up: What utility should be used for the pre-transform type? Use z.input<typeof schema> rather than z.infer, because z.infer denotes the output type.

  • z.input
  • z.infer
  • .transform()
  • z.preprocess()
  • z.codec

Source: Basic usage. Checked 2026-10-15.