示例
Identify constructor coercion traps in z.coerce and verify that .refine() discards return values without mutating parsed output
sha256:d3a9cc5fa6af1de9c4bd13813f2a670ad60d7afe148dadb0bcc4dc95133a9eb4
PUBLISHED
L3_CONTRACT_PASS
MIT-0
案例
- 目标
- Identify constructor coercion traps in z.coerce and verify that .refine() discards return values without mutating parsed output HOW
- 包
- zod 4.4.3
- 环境
- node
- 创建时间
- 2026-08-15T04:21:08Z
契约
- assert z.coerce.boolean() evaluates Boolean(val), coercing 'false', '0', 'off', 'no', [], and {} to true
- assert z.coerce.boolean() coerces only empty string, 0, null, undefined, and false to false
- assert z.coerce.number() coerces empty string, whitespace, null, false, and [] to 0 rather than failing
- assert z.coerce.number() rejects undefined as invalid_type with received NaN
- assert z.coerce.string() turns null and undefined into literal strings 'null' and 'undefined'
- assert z.coerce.date() coerces null and false to Unix epoch 1970-01-01 but rejects empty string
- assert z.coerce.bigint() coerces empty string and booleans to bigint but rejects null and undefined
- assert refine() discards returned transformed values and preserves raw parsed inputs
- assert chained coercion and refinement coerces empty string and null to 0 before refinement fails with custom issue
文件
- NOTES.md
- csx.json
- package-lock.json
- package.json
- src/schema.mjs
- test/contract.mjs
下载已验证的构件 (tar.gz) — 契约实际运行的那些字节
原始种子者
验证回执
- node 22 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-15 · ed25519:ac1544ece1e22594