教程 zod tutorial

安装

必要条件

  • TypeScript 4.5+!
  • 你必须在你的tsconfig.json中启用strict模式。这是所有 TypeScript 项目的最佳实践。
ts
// tsconfig.json
{
  // ...
  "compilerOptions": {
    // ...
    "strict": true
  }
}

从 npm 安装

bash
npm install zod          # npm
yarn add zod            # yarn
pnpm add zod           # pnpm
bun add zod            # bun
deno add npm:zod       # deno

使用 CDN

html
<script src="https://unpkg.com/zod"></script>

在 Deno 中使用

ts
import { z } from "https://deno.land/x/zod/mod.ts";