TypeScript Patterns I Actually Reach For
This isn't a list of TypeScript tricks. It's a list of the patterns that showed up, unprompted, in every large TypeScript codebase I've worked in or reviewed.
1. Discriminated Unions for State Machines
The moment you have state that can be in one of several distinct shapes, reach for a discriminated union instead of an object with optional fields.
TypeScript will force you to handle all cases when you switch on status.
That's the feature.
2. satisfies for Config Objects
satisfies lets you validate a value against a type while preserving
the literal type of the value itself.
3. Branded Types for IDs
When you have multiple ID types (userId, postId, orderId), a plain string
type won't stop you from accidentally passing the wrong one.
4. Omit + Pick in API Layers
Rather than duplicating types between your DB model and API response, compose them.
The Underlying Principle
Good TypeScript isn't about making the type system do gymnastics. It's about encoding your domain's rules into types so the compiler can catch the bugs your brain misses at 11pm.
Simple, explicit types. Discriminated unions. Avoid any. That's most of it.
Jason Lima
Software engineer. Writing about systems, craft, and real products. Say hello →