Type-safe patterns for building large-scale TypeScript applications — discriminated unions, branded types, and generic constraints.