This repository serves as a demonstration for utilizing the Zod library in a TypeScript project. Zod is a powerful TypeScript-first schema declaration and validation library that simplifies handling complex data structures.
Before you begin, ensure that you have Node.js, npm, and TypeScript installed on your machine.
- Clone the repository:
git clone https://github.com/vkpatva/zod-examples
- Navigate to the project directory:
cd zod-examples
- Install the dependencies:
npm install
- Build the TypeScript files:
npm run build
The main purpose of this demo is to showcase how Zod can be used to validate API data schemas in a TypeScript project. There are three example scripts you can use to explore different scenarios:
- Start a script using Zod for validation:
npm run start-zod
- Start a script without using Zod:
npm run start-withoutZod
- Start another example script without using Zod:
npm run start-example
- Example script for DataValidation:
npm run DataValidation
- Example script for coersion:
npm run coersion
Feel free to explore and modify the examples in the TypeScript files (withZod.ts
, withoutZod.ts
, withoutZod2.ts
) to suit your specific use case.
This project was inspired by Jimmydalecleveland's Zod Introduction Video. You can also check out the original source code on GitHub.