Introducing: @traversable/zod

A few weeks ago I released a TypeScript library called @traversable/zod.

This post covers what the library does, and highlights a few of its unique features.

Note:
Currently @traversable/zod only works with the latest version of Zod (v4).

Cover ph…


This content originally appeared on DEV Community and was authored by andrew jarrett

A few weeks ago I released a TypeScript library called @traversable/zod.

This post covers what the library does, and highlights a few of its unique features.

Note:
Currently @traversable/zod only works with the latest version of Zod (v4).

Cover photo credit:
Jack Noble, Mob Psycho 100 モブサイコ100

What makes @traversable/zod different?

@traversable/zod can be used in 2 ways:

  1. Pick one of over 25 transformers available off-the-shelf
  2. Hand-roll your own custom transformer

Off-the-shelf

ᯓ📦 zx.check

ᯓ📦 zx.deepClone

ᯓ📦 zx.deepEqual

ᯓ📦 zx.deepPartial

ᯓ📦 zx.toString

  • Converts a Zod schema into a string

  • Useful for testing, codegen, sanity checking

ᯓ📦 zx.toType

  • Converts a Zod schema into a TypeScript type

  • Preserves schema metadata as JSDoc annotations

ᯓ📦 zx.makeLens

  • 🔍 Focus nested values with lenses (getters/setters)

  • 🌈 Reify control flow with prisms (pattern-matchers)

  • ⛰️ Map over containers with traversals (for-loops)

  • 🧱 Stack them together with function composition

Roll your own

ᯓ📦 zx.fold

All the off-the-shelf transformers that @traversable/zod ships are powered by zx.fold.

Under the hood, the library uses an abstraction called recursion schemes that make implementing recursion simple and fun.

To demonstrate, I used it to implement toJsonSchema.

The implementation is so minimal (28 lines!) that I've embedded it here, in its entirety:

Note:

I specifically chose toJsonSchema because multiple libraries already exist that do this, including Zod itself.

The goal is to showcase how you can use zx.fold to build a library of your own.

Closing thoughts

Thanks for reading!

If you have any feedback, feature requests, or questions, feel free to open an issue or start a discussion.

Links

  1. @traversable/zod on GitHub
  2. The full toJsonSchema demo


This content originally appeared on DEV Community and was authored by andrew jarrett


Print Share Comment Cite Upload Translate Updates
APA

andrew jarrett | Sciencx (2025-09-02T13:10:19+00:00) Introducing: @traversable/zod. Retrieved from https://www.scien.cx/2025/09/02/introducing-traversable-zod/

MLA
" » Introducing: @traversable/zod." andrew jarrett | Sciencx - Tuesday September 2, 2025, https://www.scien.cx/2025/09/02/introducing-traversable-zod/
HARVARD
andrew jarrett | Sciencx Tuesday September 2, 2025 » Introducing: @traversable/zod., viewed ,<https://www.scien.cx/2025/09/02/introducing-traversable-zod/>
VANCOUVER
andrew jarrett | Sciencx - » Introducing: @traversable/zod. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/02/introducing-traversable-zod/
CHICAGO
" » Introducing: @traversable/zod." andrew jarrett | Sciencx - Accessed . https://www.scien.cx/2025/09/02/introducing-traversable-zod/
IEEE
" » Introducing: @traversable/zod." andrew jarrett | Sciencx [Online]. Available: https://www.scien.cx/2025/09/02/introducing-traversable-zod/. [Accessed: ]
rf:citation
» Introducing: @traversable/zod | andrew jarrett | Sciencx | https://www.scien.cx/2025/09/02/introducing-traversable-zod/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.