August 30, 2026
TypeScript Patterns I Keep Coming Back To
A collection of TypeScript patterns that have genuinely improved the quality and maintainability of my codebases.
After years of writing TypeScript, a few patterns have become non-negotiable in every project I touch.
Discriminated unions for state management. Instead of a bunch of boolean flags (isLoading, hasError, isSuccess), model your state as a union of distinct shapes. The compiler tells you when you have not handled a case, which is exactly the kind of safety you want.
The satisfies operator for config objects. It validates that an object conforms to a type without losing the literal types of the values. Perfect for route configs, theme tokens, and permission maps.
Branded types for domain primitives. Wrapping a string in a UserId brand prevents you from accidentally passing an OrderId where a UserId is expected. The overhead is zero at runtime — it is purely a compile-time constraint.
