TypeScript Refactor
When to Use
- •Simplifying code structure (extract functions, reduce nesting, split modules).
- •Applying style or idiom rules (imports, naming, types).
- •Improving type safety (replacing
any, adding explicit types, narrowing). - •Reducing duplication or improving readability without changing behaviour.
Principles
- •Behaviour first: Refactors must not change observable behaviour. Rely on existing tests.
- •Incremental: Prefer small, reviewable steps. One logical change per step.
- •Types: Preserve or improve type safety; do not introduce
anyor suppress errors without justification. - •Verification: After refactor run typecheck, tests, and lint; confirm no new failures.