TypeScript Refactoring Patterns Core Principles 1. Type Narrowing Over Type Assertions - Use type guards and discriminated unions instead of casts 2. Const Assertions for Literals - Use for immutable literal types 3. Generic Constraints - Prefer constraints over 4. Branded Types - Use branded types for domain-specific validation Refactoring Patterns Extract Discriminated Union When you see multiple boolean flags, refactor to discriminated union: Replace Conditional with Polymorphism When you see switch statements on type, use the strategy pattern: Extract Type Guard When narrowing types, crea…