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

Zod · Type Alias

input

z.input extracts the TypeScript input type of a Zod schema. It is useful when a schema’s accepted input differs from its parsed output, such as with coercion or preprocessing.

How it works

z.input is a TypeScript utility type that derives the input type associated with a Zod schema. It is especially useful when a schema transforms or coerces values, because the accepted input can differ from the parsed output.

Syntax

z.input<typeof schema>

Parameters

NameTypeDescription
schematypeof schemaA Zod schema type, supplied through typeof schema, whose input type should be extracted.

Returns

The TypeScript input type associated with the supplied Zod schema.

Key points

  • Apply z.input to a schema value with typeof to extract its accepted TypeScript input type.
  • Coercion helpers expose unknown as their default input type.
  • A coercion helper can receive a generic argument when its input should be narrower than unknown.
  • Preprocess schemas likewise use unknown for input unless the preprocessor input is narrowed.

Common mistakes

  • For coerced schemas, z.input<typeof schema> is unknown unless the schema's input generic is made more specific.
  • Preprocessing schemas also default to an unknown input type because the preprocessor may receive arbitrary values.

Example: Extract a schema's input type

import { z } from "zod";

const schema = z.coerce.number();
type Input = z.input<typeof schema>;
type Output = z.output<typeof schema>;

const value: Input = "42";
const parsed: Output = schema.parse(value);
console.log(parsed); // 42

z.input extracts the TypeScript type accepted by a schema, while parsing produces the schema's output type.

When to use it

Model transformed inputs

A schema accepts one type but parses to another, so application types must describe the pre-parse value.

Type coercion boundaries

A coercion schema receives external values whose compile-time type is broader than its output.

Constrain preprocessing

A preprocessing function needs an explicit input annotation to avoid an overly broad inferred type.

Interview questions

QWhat does z.input do?

z.input<typeof schema> extracts the type accepted as input by a schema. It differs from z.infer<typeof schema> when transformations or coercion make the input and output types different.

Follow-up: How would you obtain the parsed type? Use z.output<typeof schema>; z.infer<typeof schema> is also the schema's output type.

QWhat input type does a coerced schema expose by default?

For z.coerce schemas, the input type defaults to unknown, while the output type reflects the coerced schema. This models the fact that coercion can accept arbitrary runtime input.

Follow-up: How can the input be narrowed? Pass a more specific generic parameter to the coercion helper.

QWhy is preprocess input usually unknown?

A z.preprocess() schema also defaults to unknown input because preprocessing is designed to handle arbitrary values. The preprocessor's parameter can be annotated directly to narrow that input type.

Follow-up: Why can input and output differ? Preprocessing or transformation changes the value before or during parsing, so the accepted and produced types need not match.

  • z.output
  • z.infer
  • z.coerce
  • z.preprocess
  • ZodType

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