What is TypeScript?
You would have probably heard the word ‘typescript’ before. In 2019, TypeScript was the 7th most-used and the 5th fastest-growing language on GitHub.
The development community strongly associated TypeScript with Angular in the early days. That was because Angular forces you to use TypeScript, though overriding this is possible.
TypeScript introduced a wide number of features taken from object-oriented programming including,
- enumerated types
To sum up the differences,
- TS is known as an Object Oriented Programming language while JS is known as a scripting language(Although JS is Object Oriented)
- TS includes support for optional parameters while JS does not support it.
- TS has a feature known as static typing while JS has no such feature.
- TS supports interfaces while JS does not.
Why should you use TypeScript ?
- TS points out the compilation errors at the time of development only. While JS errors are always on run-time.
- By strict typing, you know what type of data you’re working with. Your code is more “self-documenting” as it is understandable by everyone.
- TS is popular and is used by big players in the industry. Companies like Asana, Circle CI and Slack use TS.
Why should you NOT use TypeScript?
- TS needs to be compiled. This means that your code takes some time to be compiled from TS into JS.
- The strict types can become complicated with time. This is quite common when your project gets larger.
- Although TS is strictly typed, there can be instances where the compiler did not find any errors. As we deal with JS after compilation, errors can go unchecked. This is quite rare as compilers are getting better with time.
Here comes the question,
“Which one is better?”
Due to the nature of TS, it is gaining popularity. But always keep in mind that TS can never replace JS as at the end of the day, JS is the core of TS.
It is always up to the developer to make the final decision. If you are comfortable with strictly typed languages then you can go for TS. But if you have been working with JS for a long time, it is up to you to take the leap and learn something new or to stick with your strength.
That is the end of this article. Visit my portfolio to know more about me.
Hope you learnt something. Happy learning.