How Relevant is Still TypeScript in 2021?
TypeScript just turned 9 years old, and it’s more popular than it’s ever been. As a matter of fact – it’s close to becoming the de facto standard for most JavaScript projects being started today. But is it still the best choice in 2021?
In this article, we’ll look at some of TypeScript’s main benefits, and what alternatives are out there.
The benefits of TypeScript in 2021
In order to look at how relevant TypeScript really is, we need to look at the main benefits we get from using it in our codebases. Here are some of the main upsides from going from .js to .ts:
A really good type system
Applying a type system to your codebase makes you much more confident your code will work. You can specify what kind of arguments are required, and enforce those constraints with near-instant compiler feedback. This makes it much easier to remember to cover all edge-cases, and to write clean, expressive APIs.
TypeScript has kept on improving its type system, adding improved type inference and even template string type support in later versions. All of these continuous improvements has made TypeScript’s type system pretty bullet proof over the years. Now, if they could only make those error messages a bit more readable 😅
Easy to adopt
One of my favorite things about TypeScript, is how easy it is to introduce into your codebase. Since all JavaScript is valid TypeScript, you can incrementally translate file by file until you’re all the way there. I’ve done it with several of the projects I’ve worked with, and it’s always been a success story.
Another upside is that you can move from very general types (like any
or unknown[]
) to more specific ones whenever you have the time. Iterating on your types like this – especially while developing a new function or class – makes the typing process incredibly smooth.
A little caveat here - by adopting TypeScript gradually, you’re going into a weird state of “type limbo” for a while, where you’ll have some, but not complete type safety. Just make sure you push on through to where all of your codebase is transitioned into the warm grasp of type safety.
Very popular
As a JavaScript developer, you know that one of JS’s greatest assets is its enormous ecosystem. There isn’t a use case I can think of that doesn’t have at least 10 competing packages on NPM. Being able to use these packages with a type system of choice is paramount to how nice it will feel to work with.
Luckily, TypeScript has become so popular, you’re able to find typings for most popular libraries out there. They’re either bundled (added by both maintainers and community members), or available through the community driven Definitely Typed repo. In other words - interacting with external packages is just about as easy as with regular JavaScript.
Actively maintained
TypeScript is actively maintained and developed by no other than Microsoft, the new knight in shining armor of open source software. With their financial means, the TypeScript team is sure to keep on improving both the language and the tooling surrounding it.
Being owned and operated by a tech behemoth hasn’t stopped a huge community from forming though, and the development process has been made much more open and collaborative over the years. With both a substantial backer, and a tight-knit community, TypeScript is sure to thrive for the foreseeable future.
The alternatives
Even though TypeScript might be leading the popularity wars, it’s far from being the only alternative to using JavaScript. Here are some of the most promising challengers:
Dart
Dart has been around for a few years, but has really blossomed the last couple of years. One of the main reasons of its latest upswing in popularity is the cross platform app development platform Flutter, and how it’s used there.
Dart looks a lot like JavaScript, but comes with some pretty powerful static analysis tool, as well as a dynamic type checker. Another feature is that it can be compiled down to run on native devices, without a JavaScript runtime in between. That means lightning speeds and some pretty neat features. It can even be compiled into JavaScript if you need it to.
That being said, Dart has a much smaller community behind it than TypeScript has, which comes with a bunch of tradeoffs. It’s a different language with different syntax, and it feels more like learning a new language than adding a few features to an existing one, like TypeScript does. Finally, there’s no incremental adoption path for Dart - it’s all or nothing.
You can read a much more in-depth analysis of Dart vs TypeScript here.
Elm
Elm is a functional language that compiles down to highly optimized JavaScript. It has been gaining traction for quite some time, and it’s been used to build really sturdy applications in a lot of different contexts. It is multi-purpose, but it really shines when you write single page applications!
Elm is known for two things - having the “world’s most polite compiler”, and guaranteeing you no runtime errors. The compiler comes with really nice suggestions whenever you goof up, making it a lot easier to pick up the unfamiliar syntax. The no runtime errors guarantee is nothing short of extraordinary, but it comes with a lot of restrictions to how you can do things.
Elm is a functional language, with a different syntax than you’re probably used to. It’s a pretty big leap from JavaScript, but it teaches you a ton of great lessons you can bring with you back into JavaScript land (if you ever venture back, that is).
There are still a few features missing, like code splitting, but if you’re building small apps, or have a micro frontend architecture, this might be right up your alley. Read more at elm-lang.org.
Flow
A couple of years ago, Facebook’s own type system – Flow – was competing neck and neck with TypeScript for the crown of type systems. Flow’s claim to fame was that you really didn’t need to write that many type definitions; great type inference and refinements would give you precise types at breakneck speeds.
Flow is pretty simple to get started with - you add // @flow
to the top of a regular .js file, and that will opt it in to the Flow type checker. That makes it great for adopting file by file, and porting existing JavaScript code to something with better types.
Flow is backed by Facebook. This used to be a great asset - some of the world’s greatest developers would be working on this codebase non stop! It made Flow gain traction and build a huge community quickly. However, soon, the Flow team had to prioritize Facebook’s internal needs over the wants of the community.
Flow is still a great tool, but its popularity has fallen drastically the last couple of years. It might be the right fit for you, but be ready to implement a few type definitions yourself.
Open Source Session Replay
OpenReplay is an open-source, session replay suite that lets you see what users do on your web app, helping you troubleshoot issues faster. OpenReplay is self-hosted for full control over your data.
Start enjoying your debugging experience - start using OpenReplay for free.
So… Is TypeScript still relevant in 2021?
Let’s be honest - TypeScript is a great choice for any JavaScript-based project. It has a great community, is very popular, is consistently gaining features and will be maintained for the foreseeable future.
There are some great alternatives out there, but to me at least, TypeScript is still the best tradeoff between community, features and adaptability. What do you think?