TypeScript to Zod Schema

Convert TypeScript interfaces and type aliases to Zod validation schemas instantly. Handles unions, optional fields, arrays, enums, nested objects, and cross-references. Free, runs in your browser.

100% Client-Side Your data never leaves your browser Free · No Sign-Up
TypeScript Input
Zod Schema Output

How to Use

  1. Paste your TypeScript interface or type declarations into the left panel.
  2. The tool validates and converts in real time (300 ms debounce after typing stops).
  3. Click Generate Zod Schema to force a conversion.
  4. Click Copy to copy the Zod output to your clipboard.
  5. Paste the result into your project — the output already includes the import statement and export type inference lines.

Supported TypeScript Features

  • Basic types: string, number, boolean, null, undefined, any, unknown, void, never, bigint, symbol
  • Optional properties: prop?: type.optional()
  • Union types: A | Bz.union([A, B])
  • String enums: “a” | “b” | “c”z.enum([“a”, “b”, “c”])
  • Arrays: T[] / Array<T>z.array(T)
  • Nested objects: inline object types → z.object({})
  • Cross-references: named types reference each other → Schema constants
  • Readonly: readonly modifier is accepted and ignored (Zod schemas are immutable by default)
  • Utility types: Partial<T>, Record<K, V>, Promise<T>
  • Intersection types: A & Bz.intersection(A, B)
  • Tuples: [A, B]z.tuple([A, B])
  • Literal types: “value”, 42, truez.literal()

Example

Given this TypeScript input:

interface Address {
street: string;
city: string;
zipCode?: string;
}

export interface User {
id: number;
name: string;
role: "admin" | "user" | "guest";
age?: number;
isActive: boolean;
tags: string[];
address: Address;
}

export type Status = "active" | "inactive" | "pending";

The tool generates:

import { z } from "zod";

export const AddressSchema = z.object({
street: z.string(),
city: z.string(),
zipCode: z.string().optional(),
});
export type Address = z.infer<typeof AddressSchema>;

export const UserSchema = z.object({
id: z.number(),
name: z.string(),
role: z.enum(["admin", "user", "guest"]),
age: z.number().optional(),
isActive: z.boolean(),
tags: z.array(z.string()),
address: AddressSchema,
});
export type User = z.infer<typeof UserSchema>;

export const StatusSchema = z.enum(["active", "inactive", "pending"]);
export type Status = z.infer<typeof StatusSchema>;

FAQ

What TypeScript constructs does this tool support?

It supports interface and type alias declarations, including basic types (string, number, boolean, null, undefined, any, unknown), optional properties (?), union types (A | B), string enums (literal unions), arrays (T[] and Array<T>), nested inline objects, cross-references between declared types, and generic utilities like Partial<T>, Record<K, V>, Array<T>, and Promise<T>.

How are cross-references between types handled?

If you declare multiple interfaces or type aliases in the input, any reference to a declared type by name is replaced with its Schema constant. For example, a field typed as Address becomes AddressSchema in the output. Types not declared in the input become z.unknown() with a comment.

What Zod version does the output target?

The generated schemas are compatible with Zod v3 and Zod v4. The output uses standard APIs: z.object(), z.string(), z.union(), z.enum(), z.array(), z.optional(), z.literal(), z.record(), and z.infer<>.

How does the tool handle string union types?

A union of string literals like "admin" | "user" | "guest" is automatically converted to z.enum(["admin", "user", "guest"]) for conciseness. Mixed unions (e.g. string | null) use z.union([z.string(), z.null()]).

Can I convert TypeScript class or generic type definitions?

Classes and generics are outside the MVP scope. The tool focuses on interface and type alias conversions. Generic type parameters (like T in Partial<T>) in the declared types' own signature are not expanded. Generic utility types applied to concrete types (Array<string>, Record<string, number>) are supported.

Is my code sent to a server?

No. The entire TypeScript parser and Zod code generator run in your browser. No source code leaves your machine.