Chapter 10. Modernization and Migration
You’ve heard that TypeScript is great. You also know from painful experience that maintaining your 15-year-old, 100,000-line JavaScript library isn’t. If only it could become a TypeScript library!
This chapter offers some advice about migrating your JavaScript project to TypeScript without losing your sanity or abandoning the effort.
The less code you have, the easier it will be to migrate. So it’s a good idea to remove deprecated features and do a round of dead code elimination before you start a TypeScript migration. You may want to hold off on other forms of modernization, however: converting a jQuery web app to React will actually be much easier once you’ve adopted TypeScript.
Only the smallest codebases can be migrated in one fell swoop. The key for larger projects is to migrate gradually. Item 81 discusses how to do this. For a long migration, it’s essential to track your progress and make sure you don’t backslide. This creates a sense of momentum and inevitability to the change. Item 82 discusses ways to do this.
Migrating a large project to TypeScript won’t necessarily be easy, but it does offer a huge potential upside. A 2017 study found that 15% of bugs fixed in JavaScript projects on GitHub could have been prevented with TypeScript.1 Even more impressive, a survey of 6 months’ worth of postmortems at Airbnb found that 38% of them could have been prevented by TypeScript.2 If you’re advocating for TypeScript at your organization, ...
Get Effective TypeScript, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.