TypeScript Patterns Every Senior Frontend Developer Should Own
Discriminated unions, generics and the patterns that turn TypeScript from a linter into a design tool.
Types are your first design review
The most valuable TypeScript isn't the annotation that makes the compiler happy — it's the type that makes an impossible state unrepresentable. When your types prevent invalid combinations, whole classes of bugs disappear before a single test runs.
Discriminated unions are the workhorse here. Instead of optional flags that drift out of sync, model states as a union of tagged objects. The compiler then checks every branch exhaustively, and refactoring becomes a guided walk through the compiler's errors.
Generics without the ceremony
Generics don't need to be abstract art. The best generic is the one that says 'whatever type you give me, I'll give it back safely' — like a typed wrapper around an API response or a utility that preserves the input's shape. If you're writing three levels of constraints, you're probably overcomplicating it.
Prefer narrowing over casting. Every `as` is a promise you're making to the compiler — and a place where the truth can silently diverge from the model.
Make the compiler do the remembering
The senior move is using the type system as documentation that can't go stale. Derive types from data and APIs, avoid duplicating shapes by hand, and let `satisfies` and `as const` keep your literals honest. When the code is the source of truth, the docs never lie.