What problem does it solve?
TypeScript refactors often introduce unsafe type casts, leaky abstractions, and compiler slowdowns, especially when codebases grow and generics and unions become complex.
Core Features & Use Cases
- Type architecture and modeling: Discriminated unions, branded types, and readonly-by-default patterns to prevent invalid states and domain mix-ups.
- Safer type narrowing: Custom type guards, assertion functions, and exhaustive switch techniques that eliminate most
as casts.
- Modern TypeScript and performance: satisfies,
using-based cleanup, and compiler-friendly rules like avoiding deep recursion and minimizing large union comparisons.
- Typical use case: When modernizing a backend service, use the rules to redesign error and event types as discriminated unions, enforce exhaustive handling, and reduce type-checking overhead across module boundaries.
Quick Start
Apply the typescript-refactor skill to refactor the TypeScript module by replacing unsafe casts with narrowing, redesigning key domain models using discriminated unions and branded types, and updating the code to modern TypeScript idioms while checking compiler-performance hotspots.