Commit 9ea2bc5
authored
fix(docs): FieldSchema.extend() does not exist — the FAQ recommended a call that throws (#3890)
#3882 brought content/docs under the example type-check gate and left the open
question: of the ~600 blocks still unmarked, is any GENUINE ROT rather than a
fragment? Swept them. One real one.
deployment/troubleshooting.mdx answered "How do I extend a built-in schema?" —
a direct FAQ, not a sketch — with `FieldSchema.extend({ … })`. FieldSchema carries
a .transform() that lowers author-facing sugar at parse time, so the exported
value is a ZodPipe, not a ZodObject: `.extend` is undefined and the call throws.
The example also used `z` without importing it.
Rewritten to COMPOSE — parse with FieldSchema, validate the additions alongside
it — verified to both type-check and run, and marked so the gate holds it.
Composition also keeps the transform, which .extend() would discard.
A divergence found while fixing it: the first attempt used FieldSchema.in.extend()
and failed in CI with "Property 'in' does not exist on type 'ZodObject<…>'". The
two builds emit DIFFERENT declarations for the same source — locally
ZodPipe<ZodObject<…>>, in CI a plain ZodObject — while the runtime is unambiguous
(bound ZodPipe, .extend undefined, confirmed after rm -rf dist && pnpm build). So
CI's declaration contradicts the value it describes. Likely inference instability
in the DTS bundling of these very large zod types; worth its own investigation.
The final example uses only .parse(), so it is correct under either declaration.
The sweep's METHOD is recorded in the gate docstring, because two traps make a
naive pass report a confident "nothing found":
1. tsc stops after syntactic diagnostics and never runs the semantic pass.
Marking all 780 blocks at once let ~200 broken fragments suppress
type-checking for every other block; that run returned only TS1xxx codes,
which reads exactly like "no rot" and proves nothing. Caught by injecting a
deliberate type error and watching it go unreported.
2. Unimported type names resolve against the DOM lib — Plugin, Event, Response,
Storage all exist there. A block missing its import reports "'version' does
not exist in type 'Plugin'" against lib.dom's Plugin: an artefact, not drift.
Three of the strongest-looking candidates were exactly this.
Everything else is fragments, plus config-resolution.mdx, whose aspirational
snippets a callout on the page already labels as design intent.
Gate: 196 -> 197 checked examples.1 parent 7ef20d0 commit 9ea2bc5
3 files changed
Lines changed: 97 additions & 4 deletions
File tree
- .changeset
- content/docs/deployment
- packages/spec/scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
362 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
363 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
364 | 372 | | |
| 373 | + | |
365 | 374 | | |
366 | 375 | | |
367 | | - | |
368 | | - | |
369 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
370 | 383 | | |
371 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
372 | 391 | | |
373 | 392 | | |
374 | 393 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
25 | 45 | | |
26 | 46 | | |
27 | 47 | | |
| |||
0 commit comments