10 reasons to use TypeScript

What is TypeScript?

TypeScript is an open and free programming language created in 2012 by engineers from Microsoft to create large applications. We can read from the official TypeScript webpage that “TypeScript is a superset of JavaScript that compiles to plain JavaScript”. It means that it adds additional syntax on the top of basic JavaScript. Primarily TypeScript introduces strong typing. Most of the additional syntax structures like type annotations, interfaces, generics are to ensure program semantic consistency. They are used only when developing and removed during the compilation time.

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

When writing a program In JavaScript, I think that everybody often wonders “what fields are in this object?” or “what arguments this function accepts?” – these things slow us down. We have to go through multiple files to find out where the value comes from. With TypeScript, these problems are gone (unless you’re not using it properly and placing any everywhere). 

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

If you want to use TypeScript, it’s very easy to get started with. Or maybe you already are developing an application for some time that’s already written in plain JavaScript? You can introduce TS to your existing project incrementally because it compiles also .js files. No need to rewrite your whole code. Here you can find an easy unofficial guide on how to migrate. 

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

As we said, TypeScript compiles to pure JavaScript - it means that it can run everywhere. It can be used either on the front-end of the application (for example with React, Angular or even without any framework) and with the Node.js on the back-end. 

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

Types act like another layer of documentation. They store valuable information in the code, which is extremely helpful for future software developers that will use your code. It’s a different way to communicate with your co-workers about the meaning and enforce them on how to use things that we build. Interfaces tell other people your intentions without them, for example, having to open a separate test file. From my experience, coming into the project with types was much more painless and faster in comparison to just JavaScript one. So, another time-saving. 

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.

Feel convinced?  

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. 

Navigate the changing IT landscape

Some highlighted content that we want to draw attention to to link to our other resources. It usually contains a link .