gillesdandrea/gda-skills

zod

Zod 4.5 idioms.

소스 보기

사용 방법

  1. 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
  2. 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
  3. 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/gillesdandrea/gda-skills --skill zod

시작 전 확인

  • 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
  • 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 Skill 문서

원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.

Zod 4.5

Training data skews Zod 3, and even Zod 4 knowledge usually stops at 4.0. The installed version is in package.json. Each row below names the minor that introduced it, so skip rows above the installed version.

Write the v4 idiom

Instead of (v3 habit)Write (v4)
z.string().email() / .uuid() / .url()z.email(), z.uuid(), z.url(), z.hex(), z.hash("sha256"), z.creditCard() — top-level
z.string().datetime()z.iso.datetime() (also z.iso.date(), z.iso.time(), z.iso.duration())
message: / invalid_type_error / required_error / errorMapone error: param — a string or (issue) => string
.strict() / .passthrough()z.strictObject({...}) / z.looseObject({...})
.merge(other).extend({...}); .safeExtend({...}) when the base has refinements
.deepPartial() methodz.deepPartial(schema) (4.5)
paired one-way .transform()sz.codec(inSchema, outSchema, { decode, encode }) → .decode() / .encode() / .safeDecode()
regex .refine() for a named formatz.stringFormat("name", fnOrRegex)
.optional() when the key may be absent but never undefined.exactOptional() (4.3); .exactPartial() for whole objects (4.5)
z.union where exactly one branch must matchz.xor([...]) (4.2)
hand-written JSON Schemaz.toJSONSchema(schema) / z.fromJSONSchema(json) (4.2)
z.lazy(() => Node) for a recursive objecta getter on the object: get children() { return z.array(Node); }

Added after 4.0

  • 4.1 codecs (z.codec, z.decode, z.encode), .safeExtend(), z.hash(), z.hex().
  • 4.2 z.fromJSONSchema(), z.xor(), z.looseRecord(keySchema, valueSchema) — record that tolerates keys outside the key schema.
  • 4.3 .exactOptional(), .apply(fn) for reusable check bundles, .with(...checks) alias of .check(), .brand<"Name", "in" | "out" | "inout">(), type-predicate .refine((s): s is "a" => ...) narrowing the output type, z.string().slugify(), z.map().min/max/nonempty().
  • 4.4 z.invertCodec(codec), .superRefine({ when, ... }) conditional refinement, ctx.addIssue() inside .transform().
  • 4.5 z.compile(schema) (3–9x faster parse; or import "zod/compile" at the entry point to compile everything), z.validate(schema, input): boolean for a cheap validity check, z.properties({...}) multi-property check for z.instanceof, z.input(schema) / z.output(schema) to parse against one side of a codec, z.toZod<T>()(schema) to assert a schema matches a static type, z.getDiscriminatedOption(union, value).

Facts that bite

  • Error precedence is reversed from v3: a schema-level error wins over one passed to .parse(data, { error }).
  • Refined objects are locked: .pick(), .omit(), .extend() (overwriting keys) and .merge() throw on a schema carrying refinements. Reach for .safeExtend(), or refine last.
  • `z.iso.datetime()` requires seconds since 4.5 (RFC 3339); "2024-01-01T00:00Z" fails.
  • String `.min()/.max()/.length()` count code points since 4.5, not UTF-16 units. Emoji count as one.
  • `z.object({ v: z.undefined() })` requires the key since 4.4; use .optional() for "may be absent".
  • Issue types live under z.core.$ZodIssue*; enum and literal mismatches merge into $ZodIssueInvalidValue; $ZodIssueInvalidKey and $ZodIssueInvalidElement cover record, map and set failures.
  • Unchanged and still expected: z.infer for types, safeParse at boundaries, discriminated unions, getters for recursive objects.

API detail beyond this page: Context7, library ID /websites/zod_dev.

관련 작업

같은 저장소의 Skills

더 많은 Skills

모든 Skills