The Quiet Power of TypeScript: Branded Types for Safer APIs
Branded types are the cheapest, least-known TypeScript trick that catches an entire class of bugs at compile time.
You've shipped this bug. Everyone has. A function takes a string for the user id, and one day someone passes the email instead. TypeScript doesn't blink — both are strings.
Branded types fix this without runtime cost.
type UserId = string & { readonly _brand: "UserId" };
type Email = string & { readonly _brand: "Email" };
function getUser(id: UserId) { /* ... */ }
const e: Email = "anna@x.com" as Email;
getUser(e); // ❌ Type error
Use it for IDs, monetary amounts, durations, anything that "looks like a string or number but means something specific". The type system catches the mistake before the test does.
Related articles.
- IT
Why React Server Components Are More Than Just Hype
After two years in production, RSC has matured. Here's what actually changed about how we build apps — and where the rough edges remain.
- IT
Self-Hosting Postgres in 2026: A Practical Checklist
Managed Postgres is wonderful — until the bill arrives. Here's what we learned moving 200 GB back to a self-hosted instance.
- IT
Edge Runtime vs Node.js: When the Hype Doesn't Match the Bill
Edge functions are fast — until your code hits a database. A pragmatic look at where edge wins and where it quietly loses.