Zod to TypeScript
Generate TypeScript types from Zod schemas with z.infer, z.input, z.output, and the zod-to-ts package, and choose the right direction for schema generation.
Quick answer: how do you generate TypeScript from Zod?
Use `z.infer<typeof Schema>` when you need a TypeScript type inside the same codebase. Use `z.input` and `z.output` when transforms or coercion make input and output differ. Use the `zod-to-ts` package when you need printed TypeScript declarations from Zod schemas.
Use z.infer for the common case
When the Zod schema is the source of truth, derive the TypeScript type from the schema instead of writing a duplicate interface.
import { z } from "zod";
const UserSchema = z.object({
id: z.string().uuid(),
email: z.string().email(),
role: z.enum(["admin", "member"]),
});
type User = z.infer<typeof UserSchema>;Use z.input and z.output for transforms
When a schema transforms or coerces values, the accepted input type and parsed output type can be different. `z.input` and `z.output` make that distinction visible.
const PageSizeSchema = z.coerce.number().int().min(1).max(100);
type PageSizeInput = z.input<typeof PageSizeSchema>;
type PageSizeOutput = z.output<typeof PageSizeSchema>;
const parsed = PageSizeSchema.parse("25");When to use zod-to-ts
Use the zod-to-ts package when your build needs TypeScript AST nodes or printed type aliases from Zod schemas. This is different from `z.infer`, which gives a type inside TypeScript but does not print a `.d.ts` style declaration by itself.
import { createTypeAlias, printNode, zodToTs } from "zod-to-ts";
const { node } = zodToTs(UserSchema);
const typeAlias = createTypeAlias(node, "User");
console.log(printNode(typeAlias));Zod to TS vs TS to Zod
The direction matters. Zod to TypeScript means Zod owns the runtime schema and TypeScript follows. TypeScript to Zod means existing static interfaces are converted into runtime validators.
- Use Zod to TS for new validation-first codebases.
- Use TS to Zod when DTOs already exist as interfaces or type aliases.
- Avoid maintaining both a hand-written type and a hand-written schema for the same boundary.
Unrepresentable Zod features
Printed TypeScript types cannot always express runtime behavior. Transforms, custom schemas, instance checks, and branded runtime rules may need overrides or manual comments.
- Keep runtime-only validation rules in Zod tests.
- Use generated type declarations as documentation, not as proof that runtime parsing happened.
- Review recursive schemas and helper types when printing declarations.
API boundary example
The safest pattern is to parse unknown input with Zod and export the inferred output type for application code. This prevents a static type from pretending the payload was validated.
export function parseUser(payload: unknown): User {
return UserSchema.parse(payload);
}
export type { User };Decision checklist
Before chasing the `zod-to-ts` keyword, decide whether the page should satisfy type inference, printed declaration, or opposite-direction converter intent.
- If the user wants `z.infer`, answer with direct TypeScript examples.
- If the user wants the zod-to-ts package, compare package output and limits.
- If the user wants TypeScript to Zod, route them to the FrameworkKit converter.
Zod to TypeScript workflow map
| Need | Use | Why |
|---|---|---|
| App type from schema | `z.infer<typeof Schema>` | The simplest way to derive the output type from a Zod schema. |
| Input before transforms | `z.input<typeof Schema>` | Preserves the type accepted before coercion, transform, or pipe output changes. |
| Output after parsing | `z.output<typeof Schema>` | Makes parsed data explicit; equivalent to z.infer for output types. |
| Printed type declarations | `zod-to-ts` package | Generates TypeScript AST/type declaration output from Zod schemas. |
Use FrameworkKit to generate the starter code, then review the output before shipping it in production.
Generate with TypeScript to Zod ConverterTypeScript and Zod resources
TypeScript to Zod Converter
Convert interfaces and type aliases into copy-ready Zod schema starters in the browser.
TypeScript to Zod examples
Review interface, type alias, literal union, nullable, Record, and local reference examples.
TypeScript to Zod guide
Learn which TypeScript features convert cleanly and which need manual Zod review.
JSON to Zod converter
Use sample JSON instead when your source of truth is a runtime API response or fixture.
Zod to JSON Schema Converter
Convert finished Zod schemas into portable JSON Schema, AJV, or OpenAPI-compatible output.
Validate API responses with Zod
Place generated Zod schemas at request and response boundaries in TypeScript apps.
Zod parse vs safeParse
Choose throwing or structured validation results after generating schema starters.
FAQ
Is z.infer the same as zod-to-ts?
No. z.infer extracts a TypeScript type inside your code. zod-to-ts is a package that can generate TypeScript AST nodes or printed type declarations from Zod schemas.
When should I use z.input and z.output?
Use them when a schema has coercion, transforms, or pipes, because accepted input and parsed output can differ.
Does FrameworkKit have a Zod to TypeScript converter?
The current live converter is the opposite direction: TypeScript to Zod. This guide explains Zod to TypeScript choices and points to z.infer or zod-to-ts when Zod owns the schema.
Can zod-to-ts represent transforms?
Not always. Runtime transforms and custom validation behavior may need manual overrides or separate documentation because TypeScript types cannot execute validation.
Related tools
JSON to Zod Converter
Convert JSON to Zod schemas with strict objects, optional field inference, and inferred TypeScript types.
Zod to JSON Schema Converter
Use a free browser-only online converter to turn Zod 4 schemas into JSON Schema for Draft 2020-12, Draft 7, AJV, or OpenAPI-compatible output.
OpenAPI to Zod
Turn OpenAPI schemas into Zod validators and lightweight typed fetch clients.