Post-Migration Cleanup Phase
You'll learn strategies for systematically removing the @ts-ignore and any escape hatches left behind after automated migration, replacing them with proper TypeScript types.
The Reality After Automated Migration
When you've used a tool like ts-migrate to convert a large JavaScript codebase to TypeScript, you've won half the battle—your files now have .ts extensions and compile successfully. But here's the uncomfortable truth: your code is likely riddled with @ts-ignore comments and any types that suppress errors rather than solve them.
Think of it like using duct tape to pass a building inspection. The building is technically "fixed," but it's not really safe—you've just hidden the problems. The cleanup phase is where you replace that duct tape with proper repairs.
The Systematic Cleanup Strategy
1. Inventory Your Technical Debt
Before you start randomly fixing things, understand what you're dealing with. Search your codebase for @ts-ignore, @ts-expect-error, and explicit any annotations. Track them in a spreadsheet or issue tracker by category:
- Function signatures with
anyparameters - API response handling without types
- DOM manipulation suppressions
- Third-party library boundaries
2. Prioritize by Impact
Not all suppressions are equally dangerous. Focus first on:
- Public API surfaces (functions other modules call)
- Data entry points (API responses, user input)
- Frequently modified code paths
- Areas with recent bugs
3. Fix One Pattern at a Time
Don't jump randomly between different kinds of suppressions. If you're fixing API response handlers, complete all of them before moving to event handlers. This lets you build reusable patterns and maintain mental context.
4. Replace, Don't Just Remove
The temptation is to simply delete @ts-ignore and see what breaks. Instead:
- First write the proper type or interface
- Then add proper type guards or validation
- Finally remove the suppression
- Verify the code still works
5. Use Unknown as an Intermediate Step
When you encounter an any you can't immediately type properly, replace it with unknown. This maintains some type safety while you figure out the correct structure, forcing you to narrow before use rather than silently propagating unsafety.
6. Document What You Can't Fix
Some suppressions are legitimate—maybe they're working around a genuine TypeScript limitation or a quirky third-party library. When you encounter these, replace vague @ts-ignore with @ts-expect-error and add a comment explaining why it's needed and what would need to change to remove it.
The Cleanup Loop
Your workflow for each suppression should be:
- Understand what the code actually does at runtime
- Create proper types that match the runtime behavior
- Add validation if dealing with external data
- Remove the suppression
- Run tests to verify correctness
- Commit atomically (one fix per commit makes rollback easier)
Key Takeaway: Post-migration cleanup transforms your codebase from "technically TypeScript" to "actually type-safe" by systematically replacing escape hatches with proper types, one category at a time, prioritizing high-impact areas first.