Skip to content

docs: update z.custom example for v4 compatibility#5763

Merged
colinhacks merged 3 commits into
colinhacks:mainfrom
andrewdamelio:fix-custom-docs-example
Apr 28, 2026
Merged

docs: update z.custom example for v4 compatibility#5763
colinhacks merged 3 commits into
colinhacks:mainfrom
andrewdamelio:fix-custom-docs-example

Conversation

@andrewdamelio

Copy link
Copy Markdown
Contributor

Remove template string literal example since z.templateLiteral is now available in Zod v4. Replace with File instanceof example which better demonstrates z.custom's use case for complex types.

Fixes #5605

Remove template string literal example since z.templateLiteral is now
available in Zod v4. Replace with File instanceof example which better
demonstrates z.custom's use case for complex types.

Fixes colinhacks#5605
The File example overlapped with z.file(); switch to a duck-typed
PromiseLike example which doesn't have a built-in equivalent, and
add cross-references to z.instanceof() and z.templateLiteral() for
the cases the previous examples covered. Reverts the v3 README
change since the template literal example is appropriate for v3.
Repository owner deleted a comment from pullfrog Bot Apr 28, 2026
@pullfrog

pullfrog Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

TL;DR — Replaces the outdated z.custom() documentation example (template string literal) with a Decimal class validation example, since z.templateLiteral() now covers that use case natively in Zod v4.

Key changes

  • Replace z.custom() example with Decimal validation — swaps the ${number}px template literal example for a decimal.js Decimal.isDecimal check, better illustrating z.custom()'s role for third-party types.
  • Add cross-references to preferred alternatives — the intro sentence now points readers to z.instanceof() for class instances and z.templateLiteral() for template literal types.

Summary | 1 file | 3 commits | base: mainfix-custom-docs-example


The previous example used a ${number}px template literal pattern to demonstrate z.custom(). Since Zod v4 ships z.templateLiteral(), that example no longer represents a realistic use case for z.custom(). The new example validates Decimal instances from the decimal.js library — a common real-world scenario where no built-in schema exists.

Before: example showed z.custom<\${number}px`>(…)with a regex check — a pattern now handled byz.templateLiteral()<br/>**After:** example shows z.custom(…)withDecimal.isDecimal`, demonstrating validation of third-party library types

packages/docs/content/api.mdx

Pullfrog  | View workflow run | via Pullfrog | Using Claude Opus𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new issues. Reviewed the following changes:

  • Replaced the PromiseLike structural duck-typing example with a simpler Decimal (from decimal.js) example for z.custom(), making the docs more approachable
  • Simplified the introductory text to focus on third-party library types rather than structural interfaces
  • Preserved the cross-references to z.instanceof() and z.templateLiteral() for related use cases

Pullfrog  | View workflow run | Using Claude Opus𝕏

@colinhacks colinhacks merged commit a1cf8a9 into colinhacks:main Apr 28, 2026
7 checks passed
@colinhacks

Copy link
Copy Markdown
Owner

Merged, thanks for chasing this down. I swapped the example to a decimal.js Decimal check on top — the File instanceof case overlaps with z.instanceof() and z.file(), while z.custom is best demonstrated on structural or third-party types where no built-in fits. Closes #5605.

Note: this comment was produced by an AI coding assistant.

@colinhacks

Copy link
Copy Markdown
Owner

Landed in Zod 4.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docs] Maybe new example for z.custom

2 participants