docs: add dynamic error message and combined refinement examples for refine()#6002
docs: add dynamic error message and combined refinement examples for refine()#6002IdanGonen wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
TL;DR — Adds a dynamic-error-message example and a combined .refine() + .superRefine() example to the .refine() section of api.mdx, fixing #5998. The dynamic-message snippet is a clean, useful addition; the combined-refinement block largely retreads ground already covered later in the same section.
Key changes
- Dynamic
errorfunction example — Adds a Zod / Zod Mini tab pair showingerror: (iss) => …${iss.input}…immediately after the existing static-stringerror:example. - Combined
.refine()+.superRefine()password example — Adds a second tab pair chaining both refinement APIs on a{ password, confirm }object, with prose framing the decision between them.
Summary | 1 file | 1 commit | base: main ← fix/refine-error-examples-5998
Dynamic error message
Before:
.refine()docs only showederror: "static string".
After: A second example showserror: (iss) => …withiss.inputinterpolated.
This part lands well. The iss.input claim is accurate (same shape used throughout error-customization.mdx) and the example is minimal.
Combined .refine() + .superRefine() section
Before:
.refine()section ended at the staticerror:example; cross-fieldpassword === confirmfirst appeared ~120 lines later underpath.
After: A combined password example with.refine()+.superRefine()is inserted directly under theerror:examples.
Two things worth reconsidering here:
The cross-field password === confirm refinement with path: ["confirm"] already exists at L2281 (in the path subsection) and again as confirmPassword at L2381 (under when). Multi-issue .superRefine() is already demonstrated at L2485 (UniqueStringArray). The new block is the third copy of essentially the same password/confirm example inside the .refine() section, which makes the page longer without adding a pattern readers can't already get from existing examples.
The prose at L2155 also reads "use .superRefine() instead", but the example then uses both APIs chained on the same schema. Either the framing should be "you can combine them" (matching the example), or the example should drop .refine() and demonstrate pure .superRefine() (matching "instead"). Right now the prose and the code are pointing in different directions.
Claude Opus | 𝕏
e9d657d to
9f1ec24
Compare
….refine() Addresses issue colinhacks#5998 by adding to the `.refine()` `error` subsection: - Dynamic error message example using `error` as a function with `iss.input` - Combined `.refine()` + `.superRefine()` example with guidance on when to use each - Best-practices note pointing users to `.superRefine()` for multi-issue scenarios Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
9f1ec24 to
d7a936a
Compare
There was a problem hiding this comment.
Note
Prior feedback addressed by dropping the combined .refine() + .superRefine() block. Only the dynamic-error-message example remains, which the prior review already endorsed as a clean addition.
Reviewed the following changes:
- Removed the combined
.refine()+.superRefine()password example and its "use.superRefine()instead" prose intro, resolving both the duplication with L2281 / L2381 / L2477 and the prose/example mismatch from the prior review. - Kept the dynamic-error-message tab pair (Zod + Zod Mini) showing
error: (iss) => …${iss.input}…, inserted directly after the static-stringerror:example.
Claude Opus | 𝕏

Fixes #5998
Add more examples of custom error messages with
.refine()to the API docs:erroroption, giving access toiss.inputto build messages based on the failing value - Combined.refine()+.superRefine(): a practical password schema example demonstrating when to use each —.refine()for simple single-message checks,.superRefine()when multiple issues or full control over issue codes/paths is needed.superRefine()section