In my previous post, one of my readers, said some very good points against typescript and is resulting in a pretty long conversion in the comments. So, I'd like to do have a final comparison.
- Strict Typing
Once declared, a variable can take only one type and can take only certain values. The compiler alerts developers to type-related mistakes, so they have no opportunity to hit the production phase. This results in less error-prone code and increase in developer productivity.
For example, we call a string specific method on an argument, we can do this without need to add an
if check because typescript will through an error if a different type of value is passed.
But static typing is not only about catching bugs. It also gives the code more structure, makes it self-documenting and more readable, speeds up debugging and refactoring.
With TypeScript, everything stays the way it was initially defined. If a variable is declared as a string, it will always be a string and won’t turn into a Boolean. This enhances the likelihood of functions working the way initially intended.
- Early spotted bugs
Researchers found that TypeScript detects 15 percent of common bugs at the compile stage. Far from a 100 percent result, this amount is still significant enough to save developers time and let them focus on correcting mistakes in the logic — rather than catching common bugs. Pushing the code through a compiler also decreases the volume of quality assurance and testing activities.
Sweet VS-Code Autocomplete
Genericswhich helps us to create quite complex dynamic typings, Nullish Coalescing (
Typescript has over 19 Million weekly downloads on NPM:
Percent of people who like/dislike typescript:
Experience Over time:
According to the [2020 SO survey], typescript is the second most loved language, surpassing python too! (https://insights.stackoverflow.com/survey/2020):
Of course, these are just numbers. Popularity doesn’t necessarily mean that something is of high quality and should be trusted. Fortunately, TypeScript also enjoys support from some truly formidable players in the tech world.
As if that wasn’t enough, tech giants like Microsoft (duh!), JetBrains, eBay, Ericsson, airbnb or Ubisoft are all open about using TypeScript—and who knows how many other enterprise-level companies have included it in their tech stack.
Extra Stage - Transpiling
To leverage the features of typescript properly, we need to create
interfacesetc and under a time constraint or a tight deadline, this may cause unnecessary delay. However, in the long run, it will save us a lot of time because a new developer will need a lot less time to understand the codebase.