npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zod4-to-ts

v0.1.3

Published

Convert [Zod v4](https://github.com/colinhacks/zod) schemas into TypeScript type definitions in a **minimalistic** and **easy-to-use** approach.

Downloads

43

Readme

zod4-to-ts

Convert Zod v4 schemas into TypeScript type definitions in a minimalistic and easy-to-use approach.


🚨 Beta warning

This package is still in beta. It is not recommended to use it in production until it reaches a stable version. The API is not yet stable and may change between versions.

🔍 Similar works

  • zod-to-typescript RECOMMENDED
    • Many more functionalities
    • Uses TypeScript API inside (more reliable)
    • 100% test coverage
    • Actively maintained
    • Doesn't support Zod v4 yet, but they're working on it. see Issue #32 for more info.
  • zod-to-ts
    • Doesn't seem to be actively maintained

✨ Features

  • ✅ Supports Zod v4 syntax
  • 🔁 Converts Zod schemas to valid TypeScript Definition
  • 🚀 Minimalistic approach
  • 🧪 100% test coverage
  • 📦 Lightweight & zero dependencies

📦 Installation

npm install zod4-to-ts
# or
yarn add zod4-to-ts

🔧 Usage

import { z } from 'zod';
import { zodToTs } from 'zod4-to-ts';

const userSchema = z.object({
	id: z.number(),
	name: z.string(),
	isAdmin: z.boolean().optional(),
});

const tsDefinition = zodToTs(userSchema);

console.log(`type Schema = ${tsDefinition}`);

Output:

type Schema = {
	id: number;
	name: string;
	isAdmin?: boolean;
};

Conversion Table

| Zod Type | TypeScript Type | | --- | --- | | z.string() | string | | z.number() | number | | z.boolean() | boolean | | z.bigint() | bigint | | z.symbol() | symbol | | z.null() | null | | z.undefined() | undefined | | z.void() | void | | z.never() | never | | z.any() | any | | z.unknown() | unknown | | z.int() | number | | z.template_literal() | string | | z.date() | Date | | z.file() | File | | z.nan() | number | | z.object() | { ... } & { [key: string]: $CATCHALL_TYPE } | | z.array() | Array<T> | | z.nullable() | $TYPE \| null | | z.optional() | $TYPE \| undefined | | z.default() | $TYPE \| undefined | | z.prefault() | $TYPE \| undefined | | z.catch() | $TYPE \| undefined | | z.promise() | Promise<$TYPE> | | z.readonly() | $TYPE | | z.nonoptional() | $TYPE | | z.success() | $TYPE | | z.lazy() | $TYPE | | z.tuple() | [$TYPE[0], $TYPE[1] ... , ...$REST_TYPE[]] | | z.union() | $TYPE[0] \| $TYPE[1] ... | | z.enum() | "A" \| "B" \| "C" ... | | z.literal() | "hello" or "A" \| "B" \| "C" ... | | z.intersection() | $LEFT_TYPE & $RIGHT_TYPE | | z.record() | Record<$KEY_TYPE, $VALUE_TYPE> | | z.map() | Map<$KEY_TYPE, $VALUE_TYPE> | | z.set() | Set<$VALUE_TYPE> | | z.transform() | UNSUPPORTED | | z.pipe() | UNSUPPORTED | | z.custom() | UNSUPPORTED |


🧠 Interface

zodToTs(schema: ZodType): string

Takes a Zod schema and returns a string representing the equivalent TypeScript type/interface definition.


🧪 Tests

This package is fully tested with 100% code coverage. Run tests using:

npm test

📄 License

MIT © 2025 Emanuele Scarsella


Made with ❤️ and Zod.