Time for TypeScript
How do you transition to a new language without breaking everything?
A decade in technology is like a lifetime in many other industries. The pace of change is relentless, and the tools and techniques that were cutting edge when you started out can quickly become outdated. The Thinking Traveller was already 10 years old when TypeScript was first released in 2012. At some point in the cycle of a new technology it becomes clear that it’s going to stick, and that it’s worth investing in.
The tricky part is: there’s never a good time. You’re always in the middle of something, and the idea of stopping to rewrite everything in a new language is daunting. But the longer you leave it, the harder it gets.
Around the time TypeScript was first being introduced to the world, there was another company that was just starting called Stripe. You’ve probably heard of them. They finally managed to make the big migration in 2022, and wrote an amazing write-up if you haven’t already read it.
In a single pull request, we converted more than 3.7 million lines of code.
Impressive! But now imagine that rather than 8,000 employees you have 80. And rather than 10 years of code you have 20. To put things into persepctive even more, not only did the iPhone not exist when The Thinking Traveller was founded, but the iPod only came out the year before.
Pulling off the plaster
Eventually though, you have to pull the plaster off and begin the transition. Because of the age of our codebase, one of the issues we have is that we have different versions of JavaScript between different parts of the codebase, so it’s hard to even have one consistent place to start from.
The way we’re tackling it is by starting with the new stuff. We’re writing all new code in TypeScript, and then gradually converting the old stuff as we touch it. At the time of writing this article, about 1/5th of our site is in TypeScript and we’re making good progress.
A new framework
We’re also taking advantage of the ‘clean slate’ by switching the framework we’re using, leveraging other modern tools and techniques that have come out since we started. We’ve embraced the Next.js framework, which has been a great choice for us, and we’re using it to build a new version of our site that will be faster, more reliable and easier to maintain.
The work continues and we’ve all found it quite strange when we have to dip back into the older parts of the codebase, immediately missing the type safety!