Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 7, 2021 05:51 am GMT

How Relevant is Still TypeScript in 2021?

by author Kristofer Selbekk

TypeScript just turned 9 years old, and its more popular than its ever been. As a matter of fact its 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, well look at some of TypeScripts 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 TypeScripts 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 youre all the way there. Ive done it with several of the projects Ive worked with, and its 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, youre going into a weird state of type limbo for a while, where youll 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 JSs greatest assets is its enormous ecosystem. There isnt a use case I can think of that doesnt 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, youre able to find typings for most popular libraries out there. Theyre 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 hasnt 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, its 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 its 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. Its 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, theres no incremental adoption path for Dart - its 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 its 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 worlds 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 youre probably used to. Its 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 youre 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, Facebooks own type system Flow was competing neck and neck with TypeScript for the crown of type systems. Flows claim to fame was that you really didnt 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 worlds 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 Facebooks 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

Debugging a web application in production may be challenging and time-consuming. OpenReplay is an Open-source alternative to FullStory, LogRocket and Hotjar. It allows you to monitor and replay everything your users do and shows how your app behaves for every issue.
Its like having your browsers inspector open while looking over your users shoulder.
OpenReplay is the only open-source alternative currently available.

OpenReplay

Happy debugging, for modern frontend teams - Start monitoring your web app for free.

So Is TypeScript still relevant in 2021?

Lets 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?


Original Link: https://dev.to/asayerio_techblog/how-relevant-is-still-typescript-in-2021-34b5

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To