Typescript vs JavaScript: The Battle of the Web Development Tools
It is September 7th, 2023 and you are watching the code report. Many years ago, in 2017, the legendary JavaScript user Kent C Dodds said, “I don’t use typescript so I don’t ever plan on supporting it.” In 2019, he goes on to say, “Your impassioned love of typescript is sort of freaking me out.” Finally, in 2023, comes the capitulation: typescript is here, and it’s only a matter of time before you are using it, whether you like it or not.
But this is the sign of a good developer – you have to be open-minded and willing to adapt to new tools, and sometimes tools you don’t even like. But the big question here is: did typescript really win? Because recently, the tables have started to turn. A bunch of big open-source projects have decided to ditch typescript in favor of vanilla JavaScript. To understand the shocking turn of events, we’ll need to go back to the very beginning.
The Rise of TypeScript
In 2012, typescript was first released by Microsoft. At first, nobody really cared, but then a few years later, it was adopted by the Angular 2 framework, which everybody thought was crazy. But here’s the thing: first, they think you’re crazy, then they fight you, then you change the world. By the early 2020s, typescript was everywhere, at which point most of its haters had been converted into true believers.
The Unexpected Backlash
Right as we’re about to reach the glorious climax of typescript saturation, big libraries like Svelte, Drizzle, and Turbo are deciding to ditch typescript from their code bases. To be clear, that just means that they’re not going to use typescript when developing these libraries. But as an end user in a framework like Svelte, for example, you’re still able to use typescript just like normal.
But how could anyone possibly go back to vanilla JS after using typescript? Did they not remember runtime errors like ‘cannot read properties of undefined’? Did they not remember how hard it is to refactor a codebase where you have no idea what anything is? These people are a lot smarter than I am, so let’s first look at this article from DHH, the creator of Ruby on Rails, who’s getting rid of typescript in Turbo Version 8.
Reasons for Ditching TypeScript
The main reason they’re getting rid of it is not because of the compile step, but rather because it pollutes the code with “type gymnastics.” And there’s a lot of truth to that, especially when developing a library. For example, DHH shared, “The main reason they’re getting rid of it is not because of the compile step, but rather because it pollutes the code with quote type gymnastics and there’s a lot of Truth to that especially when developing a Library.”
He further explains that when working on a library, he has to do his own type gymnastics with typescript just to get rid of some red squiggly lines in the IDE. But using ‘any’ just to suppress the type errors isn’t a good long-term solution, and strict mode in the compiler forces the use of explicit types that may result in code that’s anything but beautiful.
Another huge project moving away from typescript is Svelte and the reasoning is a bit different. It’s purely practical and the main benefit is no compile step, which results in a huge boost in productivity for a large framework like this. Svelte 5 and Svelte kit are already written in plain vanilla JS and they’re still getting most of the benefits of typescript using JSDoc, a standard comment format that declares types and provides intellisense in your editor.
So, is it time to just ditch typescript altogether? When it comes to building actual applications with a tool like Svelte kit or Next.js, typescript still seems to have its place. Those tools integrate TS seamlessly, and trying to get the same results with JSDoc would be a total nightmare. But there’s hope for the future, as there’s currently a stage 1 ECMAScript proposal that would add optional type annotations to JavaScript natively, thus making typescript nearly obsolete.
This has been the code report. Thanks for watching, and I will see you in the next one.