A vscode
extension which generates Zod schemas from typescript source code (using ts-to-zod package).
This extension will generate Zod
schema together with inferred types into new vscode
readonly panel.
Source typescript code:
export interface HeroContact {
/**
* The email of the hero.
*
* @format email
*/
email: string;
/**
* energy status of the hero
*/
energy: 'positive' | 'negative';
/**
* Does the hero has super power?
*
* @default true
*/
hasSuperPower?: boolean;
/**
* The age of the hero
*
* @minimum 0
* @maximum 500
*/
age: number;
}
Generated Zod schema:
// Generated by ts-to-zod (https://www.npmjs.com/package/ts-to-zod)
import { z } from "zod";
export const heroContactSchema = z.object({
/**
* The email of the hero.
*
* @format email
*/
email: z.string(),
/**
* energy status of the hero
*/
energy: z.union([z.literal("positive"), z.literal("negative")]),
/**
* Does the hero has super power?
*
* @default true
*/
hasSuperPower: z.boolean().optional(),
/**
* The age of the hero
*
* @minimum 0
* @maximum 500
*/
age: z.number()
});
// inferred types:
export type HeroContact = z.infer<typeof heroContactSchema>;
Available commands from command pallete:
Command | Keybinding |
---|---|
Generate Zod schema from Typescript | none |
press
F1
orCtrl+Shift+P
to openCommand palette
- Open Extensions sideBar panel in Visual Studio Code and choose the menu options for View → Extensions
- Search for
zodschema-generator
- Click Install
- Click Reload, if required
Marketplace extension page - Zod schema generator
Have a look at our CHANGELOG to get the details of all changes.
Initial release of Zod schema generator
extension