Package Exports
- @rexeus/typeweaver-zod-to-ts
Readme
๐โจ @rexeus/typeweaver-zod-to-ts
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
unknowntype 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