TypeScript to Zod converter

Convert TypeScript to Zod 4 schemas that validate data against your types at runtime. JSDoc tags such as @minLength, @pattern and @minimum become real checks.

TypeScript

Zod

Waiting for input

What you get

How each result is checked

  1. Your code is read by the real TypeScript compiler.
  2. Step 1: the types are converted to JSON Schema, and a round trip proves the schema accepts exactly the same values as your types.
  3. Step 2: the generated Zod schemas are run and must agree with that JSON Schema (checked with Ajv) on every test value.

What can't convert exactly

  • Put each JSDoc comment on its own line above the property it describes. TypeScript does not attach a /** */ comment written after other code on the same line, so its rules would not apply; the result names any such comment.
  • Date, functions, bigint, Map and Set have no JSON form; Date becomes an ISO date-time string and the others are reported.
  • Objects reject keys they do not declare by default (z.strictObject), which matches the types. Choose "Allow" to accept extra keys.
  • Generic types are included wherever they are used with concrete types.

Questions

Why go through JSON Schema?

Each step can then be proved: the compiler proves the types and the schema match, and the reference validator proves the schema and Zod match.

Does it keep my type names?

Yes. Each interface, type and enum becomes a Zod schema with the same name, plus an exported inferred type.

How do I convert a TypeScript interface to Zod?

Paste the interface (or several, with the types they use). Each one becomes a Zod schema with the same name, unions and enums included, and JSDoc tags such as @minLength become checks. This ts to Zod conversion is checked by the TypeScript compiler, then against a reference validator.

How do I convert TypeScript to Zod online?

Paste your TypeScript or open a file on the left (or click Example). The Zod appears on the right as you type, already checked. Copy it, or download it as a file. Nothing is uploaded.

Can the Zod output be wrong?

Every result is checked before it is shown (the checks are listed on this page). If a check fails, the page says "Review needed" and why, instead of presenting the output as correct, and anything that cannot convert exactly is named in the notes.