TypeScript · January 20, 2026
TypeScript Patterns I Actually Use
Not the ones in tutorials. The ones that show up in production code every week.
After five years of TypeScript in production, these are the patterns I reach for constantly.
Discriminated Unions for State Machines
Instead of separate loading, error, data booleans that can get into impossible states, use a discriminated union.
type FetchState<T> =
| { status: 'idle' }
| { status: 'loading' }
| { status: 'success'; data: T }
| { status: 'error'; error: string };
Now TypeScript enforces that you can’t access data when status is 'error'.
Branded Types
Use branded types to prevent confusion between values that are the same underlying type but semantically different.
type UserId = string & { readonly _brand: 'UserId' };
type SessionId = string & { readonly _brand: 'SessionId' };
satisfies Operator
The satisfies operator validates that a value matches a type without widening it. Perfect for configuration objects.