Runtime validation with Zod
I validate all data that crosses a trust boundary and rely on type inference everywhere else.
- Request bodies, query strings, webhook payloads and environment variables are parsed with Zod.
- The TypeScript type is derived from the schema with
z.infer, so there is one definition. - Inside the application, functions take already-validated domain types and don’t re-check them.
import { z } from "zod";
export const CreateOrder = z.object({
productId: z.string().min(1),
email: z.string().email(),
quantity: z.number().int().positive().max(10),
});
export type CreateOrder = z.infer<typeof CreateOrder>;
Typed content models
On static sites, I give content a schema too. This portfolio is an example: every service, technology, industry, project and article is validated at build time, and relationships between them are typed references. If a case study points at a technology page that doesn’t exist, the build fails with the exact file and field.
Shared types across a monorepo
In multi-app repositories, shared packages export their types alongside their code. When a contract changes, tsc across the workspace lists every app that needs updating before anything is deployed. This is the main reason I prefer a monorepo for products with several frontends and APIs.