JSPM

@rexeus/typeweaver-zod-to-ts

0.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q84021F
  • License Apache-2.0

Transforms Zod v4 schemas into precise TypeScript shapes. Powered by Typeweaver ๐Ÿงตโœจ

Package Exports

  • @rexeus/typeweaver-zod-to-ts

Readme

๐Ÿ”„โœจ @rexeus/typeweaver-zod-to-ts

npm version License TypeScript

This utility library provides logic for converting Zod v4 schemas into TypeScript type representations. It is used internally by typeweaver to generate TypeScript types from Zod schemas.


๐Ÿ“ฅ Installation

npm install @rexeus/typeweaver-zod-to-ts

๐Ÿ’ก How to use

import { TsTypeNode, TsTypePrinter } from "@rexeus/typeweaver-zod-to-ts";
import { z } from "zod";

// Define a Zod schema
const userSchema = z.object({
  id: z.string(),
  name: z.string(),
  email: z.string().email(),
  age: z.number().optional(),
});

// Convert to TypeScript AST node
const typeNode = TsTypeNode.fromZod(userSchema);

// Print as TypeScript type string
const typeString = TsTypePrinter.print(typeNode);
// Output: { id: string; name: string; email: string; age?: number | undefined; }

โœ๏ธ Zod Type Support

โœ… Supported Types

The library provides complete TypeScript type generation for the following Zod schema types:

  • Primitives: z.string(), z.number(), z.boolean(), z.date(), z.bigint(), z.symbol()
  • Literals: z.literal(), z.enum()
  • Collections: z.array(), z.record(), z.map(), z.set(), z.tuple()
  • Objects: z.object() with nested properties and optional fields
  • Unions: z.union()
  • Intersections: z.intersection()
  • Modifiers: z.optional(), z.nullable()
  • Special types: z.unknown(), z.any(), z.void(), z.never(), z.null(), z.undefined()
  • Async types: z.promise()

โš ๏ธ Unsupported Types

The following Zod types are not yet implemented and will fall back to unknown type:

  • Advanced types: z.lazy(), z.templateLiteral(), z.custom(), z.transform(), z.pipe()
  • Modifiers: z.nonOptional(), z.readonly(), z.default(), z.catch()
  • Special types: z.nan(), z.file(), z.success()

Note: When encountering unsupported Zod types, the library gracefully falls back to TypeScript's unknown type to maintain type safety.

๐Ÿงตโœจ About typeweaver

Typeweaver is a type-safe HTTP API framework built for API-first development with a focus on developer experience. Use typeweaver to specify your HTTP APIs in TypeScript and Zod, and generate clients, validators, routers, and more โœจ

See more of typeweaver

๐Ÿ“„ License

Apache 2.0 ยฉ Dennis Wentzien 2025