zod-ts

Validate runtime data against Zod schemas in TypeScript applications.

1|Updated Nov 26, 2014
One-click install
npx skills add https://github.com/tianhuil/dotfiles --skill zod-ts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zod-ts
Source: https://github.com/tianhuil/dotfiles/tree/main/home/.config/opencode/skills/zod-error-ts
Command: npx skills add https://github.com/tianhuil/dotfiles --skill zod-ts

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide helps developers implement robust runtime validation in TypeScript by leveraging Zod to enforce schemas and catch invalid data at the source.

Core Features & Use Cases

  • Create and compose Zod schemas for primitive, union, and nested data.
  • Validate API inputs, form data, and configuration objects with clear, actionable errors.
  • Use .parse or .safeParse to robustly handle validation results across client and server environments.

Quick Start

Create a Zod schema for your data and invoke parse on incoming data to validate it at runtime.

Frequently Asked Questions about zod-ts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate API inputs at runtime in TypeScript?

Use Zod schemas to validate API inputs at runtime in TypeScript by applying .parse or .safeParse to incoming data. This catches invalid data at the source and provides clear, actionable error messages for invalid payloads.

What is the difference between parse and safeParse in Zod?

In Zod, .parse throws an error when validation fails, whereas .safeParse returns a structured object containing success status and error details without throwing. Using safeParse allows you to robustly handle validation results across client and server environments.

Does Zod schema validation work in both Node.js and browser environments?

Yes, Zod schema validation works in both Node.js and browser environments. You can apply it consistently to validate form data, API inputs, and configuration objects on both the server and client side of your TypeScript applications.

How do I validate nested configuration objects with Zod?

To validate nested configuration objects with Zod, you compose schemas by nesting object schemas within each other. Running parse on the root object validates the entire nested data structure, providing clear error messages for any invalid nested properties.

When do I need runtime validation in TypeScript instead of static typing?

You need runtime validation in TypeScript when handling external data from API inputs, form submissions, or configuration files. Static types only apply at compile time, whereas Zod enforces schemas at runtime to catch invalid data at the source.

How to get clear error messages for invalid form data using Zod?

To get clear error messages for invalid form data, pass the data through a Zod schema using safeParse. This returns detailed error information instead of throwing, allowing you to map actionable errors back to your form fields.