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.

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.
Would this still apply on shared hosting without shell access?
Agreed. Start simple and only reach for this when you feel the pain.
Fair point. For a monorepo I would probably split the configuration per package.
A repo is on the way. I will link it in the post once it is cleaned up.
Safari 16.4 and newer are fine in our testing; older versions need the fallback line.
How does this hold up on older Safari versions? That is where we always get burned.
Shared this with my team. The list near the end is going straight into our pull request template.
The part about naming things made me laugh, then made me go rename three functions.