What is TypeScript?
Also, according to GitHub’s statistics, TypeScript is one of the fastest-growing languages.
Image: GitHub’s Octoverse
So what are the reasons why you should use TypeScript ?
1. Better developer experience
Thanks to functionalities that TypeScript comes with, it’s easier and more intuitive for a software developer to write a program. One of the main conveniences is that you know not only the name of the variable, but also what kind of data it stores. You can focus more on big stuff like logic in the application, and care less about small details.
TypeScript also saves your time because instead of having to search into documentation, when typing TS can suggest all of the available options like props in components or functions/classes in libraries. It provides you with a higher chance of using them as intended and passing correct parameters. For example, you don’t have to look into the documentation to see that you can add checked, checkedIcon props and see what type they should be to <Checkbox/> component from Material UI. Without typings, it’s easier to forget to wrap variable in an array or pass parameters in the wrong order.
Of course, the most important thing for a programmer is to learn how to write readable clean code and respect all the good practices. But if possible, why not make things easier for yourself and use external help where you are forced to do so? We are all humans and make mistakes, so using a tool that enforces us to avoid them is a life-saver.
2. Expanding your programming knowledge
By learning TypeScript, you get to know new programming concepts, that you may haven’t had contact with, like types, generics, interfaces, enums, namespaces. All of these structures were inspired by static-typed languages like C#, Java, and C++, so if you use TypeScript, it may benefit in the future when you will want to try new programming language.
3. Easy to start and adopt
4. Active community
TypeScript is getting more and more popular. It’s used by the top tech companies like Google, Microsoft, Airbnb, Shopify, Asana, Adobe, and Mozilla so we can assume that it reaches their expectations in terms of scalability - as they are developing large and complex applications.
TypeScript has also a lot of amazing open-source contributors, like DefinitelyTyped and TypeStrong, which are constantly developing TypeScript’s tooling.
Source: Github’s Octoverse
5. Runs everywhere
Another advantage of TypeScript is that it compiles to any JS versions, ES6, ES5 and down to… ES3.
6. Prevents bugs
TypeScript won't make your software bug free. But it can prevent a lot of type-related errors.
For example, if you set strictNullChecks option to true when you have a variable that can be an object or null/undefined, you can't get property of this object without checking if it isn't null/undefined.
7. Documentation + communication
Unlike any other documentation, TypeScript is always in sync with the newest changes.
Of course, it shouldn’t be a substitute for general documentation
8. Code quality
Defining data structures in the beginning, using types and interfaces, forces you to think about your app’s data structure from the start and make better design decisions.
9. Easier refactoring
When you want to rename a variable with IDE, it can only make guesses - so sometimes it ends up with unwanted changes. However, when IDE will be provided with the instrumentation of TypeScript types, then it can be 100% accurate. In pure JS it’s necessary to do a regression test of the whole system after such a refactor, which may take lots of time.
10. AOT compilation
TypeScript does everything during compilation time, so it doesn’t have a negative effect on runtime performance.
One of the examples of this can be protected and private fields introduced into the standard by ECMAScript, which has been around in TypeScript for some time. The difference is that TS is checking it at compilation, and ES during runtime – and this can affect application performance.
In this article I wanted to emphasize that types are not only to secure the application, but also have a positive impact on the frontend developer experience and in the long run, it can accelerate, not slow down the development.