Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zod-to-ts

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod-to-ts

generate TypeScript types from your Zod schema

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
226K
decreased by-0.4%
Maintainers
1
Weekly downloads
 
Created

What is zod-to-ts?

The zod-to-ts npm package is a utility that converts Zod schemas to TypeScript interfaces. This is particularly useful for ensuring type safety and consistency between your Zod validation schemas and TypeScript types.

What are zod-to-ts's main functionalities?

Convert Zod Schema to TypeScript Interface

This feature allows you to convert a Zod schema into a TypeScript interface. In the example, a Zod schema for a User object is defined and then converted into a TypeScript interface named 'User'.

const { z } = require('zod');
const { zodToTs } = require('zod-to-ts');

const UserSchema = z.object({
  id: z.number(),
  name: z.string(),
  email: z.string().email()
});

const { tsInterface } = zodToTs(UserSchema, 'User');
console.log(tsInterface);

Generate TypeScript Definitions from Zod Schemas

This feature allows you to generate TypeScript definitions from Zod schemas. In the example, a Zod schema for a Product object is defined and then converted into a TypeScript interface named 'Product'.

const { z } = require('zod');
const { zodToTs } = require('zod-to-ts');

const ProductSchema = z.object({
  id: z.number(),
  name: z.string(),
  price: z.number()
});

const { tsInterface } = zodToTs(ProductSchema, 'Product');
console.log(tsInterface);

Other packages similar to zod-to-ts

Keywords

FAQs

Package last updated on 30 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc