Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

zod

БесплатноБез исполняемых скриптовНе проверен

Zod 4 and Zod 3 rules for schema validation in TypeScript: parsing untrusted input with safeParse, object composition, refinements, transforms, codecs…

anivarот anivar★ 25 звёзд на GitHub

Об этом скилле

Zod

IMPORTANT: Your training data about zod may be outdated or incorrect. Zod 4 changed string formats, enums, error customization, issue codes, defaults and functions, and many projects still run Zod 3, whose forms Zod 4 deprecates or removes. First establish which Zod the file uses (next section). Then rely on this skill's rule files for that version and on the project's own source code as the source of truth. Do not write a Zod 4 API into a Zod 3 file, and do not keep a Zod 3 form in a Zod 4 file unless the rule for that version says it still applies.

Which Zod

Decide per file, before writing a schema. The import specifier wins; the installed version decides what the bare zod specifier means.

Evidence in the file and the project API to write
from "zod/v4", "zod/v4-mini" or "zod/mini" Zod 4
from "zod/v3" Zod 3
from "zod", and the lockfile resolves zod to 4.x Zod 4
from "zod", and the lockfile resolves zod to 3.x Zod 3
No lockfile: the zod range in package.json (^3.25.0 is Zod 3, ^4.0.0 is Zod 4) By range
Nothing resolvable Say so, default to Zod 4 (npm latest), and name the assumption in the change

Both package lines carry both APIs. [email protected] exports Zod 4 at zod/v4 and zod/v4-mini; [email protected] exports Zod 3 at zod/v3; zod.dev/v4/versioning says the subpaths stay available. A library that accepts either declares "zod": "^3.25.0 || ^4.0.0" (zod.dev/v4/versioning) and follows zod.dev/library-authors.

A Zod 4 file takes rules/ and references/ as written. For a Zod 3 file, read v3/rules/<rule-id>.md when it exists and apply that form; a rule with no Zod 3 file applies as written, and the check compiles those rules against Zod 3 to keep that true. Two rules have no Zod 3 form at all, perf-compile and perf-zod-mini; v3/references/zod-3.md lists them, with the API map by rule, the Zod 3 error model, and what parses differently between the versions. The migrate- rules describe the Zod 4 side of a migration: in a Zod 3 file their "Incorrect" forms are the correct forms until the file moves to zod/v4.

When to Use Zod

Zod is for runtime type validation — parsing untrusted data at system boundaries (API input, form data, env vars, external services). For compile-time-only types, plain TypeScript is sufficient.

Need Recommended Tool
API input/output validation Zod
Form validation (React, Vue) Zod (with react-hook-form, formik, etc.)
Env var parsing Zod (with t3-env or manual)
Compile-time types only Plain TypeScript
Strict client bundle budget Zod Mini (zod/mini), or Valibot
Maximum type inference ArkType

Rule Categories by Priority

Priority Category Impact Prefix
1 Parsing & Type Safety CRITICAL parse-
2 Schema Design CRITICAL schema-
3 Refinements & Transforms HIGH refine-
4 Error Handling HIGH error-
5 Performance & Composition MEDIUM perf-
6 v4 Migration MEDIUM migrate-
7 Advanced Patterns MEDIUM pattern-
8 Architecture & Boundaries CRITICAL/HIGH arch-
9 Observability HIGH/MEDIUM observe-

Quick Reference

1. Parsing & Type Safety (CRITICAL)

  • parse-use-safeParse — Use safeParse() for user input instead of parse() which throws
  • parse-async-required — Must use parseAsync()/safeParseAsync() when schema has async refinements
  • parse-infer-types — Use z.infer<typeof Schema> for output types; never manually duplicate types
  • parse-validate-boolean — Use .validate() for a yes or no; it narrows to the input type, so use safeParse() for the output

2. Schema Design (CRITICAL)

  • schema-object-unknowns — z.object() strips unknown keys; use strictObject or looseObject
  • schema-union-discriminated — Use z.discriminatedUnion() for tagged unions, not z.union()
  • schema-coercion-pitfalls — z.coerce.boolean() makes "false" → true; use z.stringbool()
  • schema-recursive-types — Use a getter for recursive schemas; cyclic input parses since 4.5
  • schema-json-string — z.json() does not parse a string; decode JSON text with a codec

3. Refinements & Transforms (HIGH)

  • refine-never-throw — Never throw inside .refine() or .transform(); return false, or add issues through ctx
  • refine-vs-transform — .refine() for validation, .transform() for conversion, .pipe() for staging
  • refine-cross-field — Refine the parent object and set path; .superRefine() for several issues

4. Error Handling (HIGH)

  • error-custom-messages — Use the error parameter; required_error/invalid_type_error are gone, message is deprecated
  • error-formatting — z.flattenError() for forms, z.treeifyError() for nested; formatError deprecated
  • error-input-security — Never use `report
Полный SKILL.md на GitHub

Установить zod в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

AGENTS.mdCHANGELOG.mdLICENSEREADME.md

FAQ

Что делает скилл zod?

Zod 4 and Zod 3 rules for schema validation in TypeScript: parsing untrusted input with safeParse, object composition, refinements, transforms, codecs, branded types, error messages, JSON Schema, v3 to v4 migration and schema tests. Baseline: zod ^4.6.0. Zod 3 projects: zod ^3.25.0. Use this skill whenever code imports zod or the user writes, reviews, debugs or upgrades a schema, even if they never say "zod": form, env-var and API input validation in a project that has zod installed count. Training data often has the Zod 4 API wrong, so load this before writing a schema. Triggers on: zod imports, z.object, z.infer, z.enum, safeParse, ZodError, invalid_type, "Encountered Promise during synchronous parse", "schema validation", "zod v4", "zod/v3", "zod/mini", zod-schema-faker.

Как установить скилл zod?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл zod запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить zod с