New series: what assistive tech really hears on your checkout page. Start with part one →
Shipwright
Home
TypeScript Aug 22, 2026 2 min read 181 views

Zod at the Edges, Plain Types in the Middle

June Park

June Park

@junepark

Share

Validate untrusted input once at the boundary and let inference handle the rest. TypeScript is at its best when you barely notice it. The goal of this post is fewer annotations, not more, while catching the bugs that actually reach production.

Cover illustration for the article Zod at the Edges, Plain Types in the Middle
Figure 1. Validate untrusted input once at the boundary and let inference handle the rest.

Let inference do the work

Inference covers most local code. Annotate function parameters and public return types, and let the compiler fill in everything else. If you find yourself writing as, stop and ask which check is missing.

  • Annotate parameters and exported return types.
  • Validate external data once, at the edge.
  • Prefer discriminated unions over optional flags.
  • Treat every as cast as a code smell to review.

Types at the boundary

Data that crosses a boundary, whether a network response, a form, or a query string, is untrusted until something validates it at runtime. Types alone cannot do that job, but they can make sure validation happens once.

Adding manpower to a late software project makes it later.

Fred Brooks, The Mythical Man-Month, 1975

Quick takeaway

Fewer annotations, stronger boundaries.

When to reach for generics

🔍

Inference

Let the compiler work out local types.

🛡️

Validation

Parse untrusted data at the edge.

🧬

Unions

Model states explicitly with a discriminant.

Generics look intimidating in library code, yet in application code they usually solve one problem: keeping the input and output of a helper connected. Start with a single type parameter and add more only when a test demands it.

Wrapping up

We have been running this approach for several months now. The initial setup took about a day, and the ongoing cost is close to zero once the team knows where to look.

June Park

June Park

Author

Frontend engineer working across React and TypeScript. June writes the posts she wishes she had found while debugging.

Related Posts

Comments 8

Yuki Tanaka

Would this still apply on shared hosting without shell access?

Sam Whitfield Member

Agreed. Start simple and only reach for this when you feel the pain.

Alex Moreno

Fair point. For a monorepo I would probably split the configuration per package.

Oskar Nilsson

A repo is on the way. I will link it in the post once it is cleaned up.

Sam Whitfield Member

Safari 16.4 and newer are fine in our testing; older versions need the fallback line.

Diego Alvarez

How does this hold up on older Safari versions? That is where we always get burned.

Diego Alvarez

Shared this with my team. The list near the end is going straight into our pull request template.

Priya Raman Member

The part about naming things made me laugh, then made me go rename three functions.

Leave a comment

Your email will not be published. Sign in for a faster experience.

Supports **bold**, *italic*, and `code`.