Zod → TypeScript

Infers a TypeScript interface from a Zod object schema.

Zod to TypeScript converts a Zod object schema into a matching TypeScript interface right in your browser. Paste a z.object({ ... }) definition and instantly get an export interface Schema with the correct field types, optional markers, and nested shapes. It is handy when you want a quick static type from an existing Zod validator without pulling in extra tooling or running a build step.

Common uses

  • Turn a z.object schema into an exported TypeScript interface to use as a function parameter or API response type.
  • Generate union types from z.enum members so your code only accepts the allowed string literals.
  • Map array fields like z.array(z.string()) to TypeScript array types such as string[].
  • Flatten nested z.object definitions into inline object types for quick reference.
  • Mark optional or nullish fields with a ? so the generated interface reflects which properties may be missing.

FAQ

Which Zod types does the converter support?

It handles z.string(), z.number(), z.boolean(), z.enum([...]), z.array(...), and nested z.object({...}). Optional and nullish fields are detected and rendered with a ? modifier. Unsupported types such as z.date() throw an error rather than guessing.

How are optional fields handled?

Fields ending in .optional() or .nullish() are marked with a ? in the generated interface. The check scans the whole field value, so a modifier placed anywhere in the expression flags that field as optional.

What does the generated output look like?

It always produces a single export interface Schema { ... } block. Enums become string-literal unions, arrays become element[] types, and nested objects are inlined as object types.

Why did I get an error instead of an interface?

The input must contain a z.object({ ... }) with at least one field and balanced brackets. You will get an error if no z.object is found, the object is empty, brackets are unbalanced, an enum has no members, or a field uses an unsupported Zod type.

Is my schema sent to a server?

No. The conversion runs entirely in your browser using local JavaScript, so nothing you paste is uploaded or stored anywhere.

Related tools

  • JSON → GraphQL Type
  • JSON → JSON Schema
  • JSON → Protobuf
  • JSON → TypeScript
  • JSON → Types (multi-language)
  • JSON → Zod
  • JSON Schema → Sample
  • JSON Schema → TypeScript