Photo by Fabian Grohs on Unsplash

The question about TypeScript or Flow is brought up many times at conferences, meetups and at work. It seems that people are confused when and how Types can help them, so here is a quick summary When and Why!

When to use TypeScript/ Flow — and why?

1. You have a big scale project

As TypeScript (Static types) enforces you to use typing in your code, it actually helps document the code and understand it better. The bigger the project is, the smarter it is to use typing to avoid the future mess in the code. TypeScript allows you to create more reusable parts, which will help save you time in the long run. There is a reason why Slack, Airbnb, Uber, Facebook use them.

Nope!

2. Quality of the code is important for the project

Nowadays, having eslint with airbnb rules is a standard, but TypeScript/Flow is next level. It checks your work and guides you where you might make a mistake. If you need to have a clean and bug free code, you could use the help of Type-Checking.

3. Your team is big and/or I have junior developers in a team

Everyone needs a rubber duck sometimes to share some thoughts, and Type-Checking can be yours for free. Type-Checking can validate your code in `ms` and help you navigate through your codebase. This is especially helpful for junior developers who sometimes get lost in the codebase and `undefined` is their nightmare.

4. You want to avoid ‘dummy’ testings

TypeScript cooperates with your code editor (e.g. Webstorm) and will shoot errors at you everytime you make any typing error. This doesn’t mean that you will magically have less bugs in your code, but you will notice them on an early stage — so you will be able to skip a lot of `console.log` tests. You would be surprised how often you `console.log`.

5. You refactor your code often

This is somehow connected to everything mentioned above. If you have a big code that needs to stay clean, and you need to refactor it often due to project requirement changes TypeScript will help you refactor the code faster and with a smaller amount of errors. A simple example is when we have defined interface for fetching data from some endpoint. When requirements change we need to only update our interface, but immediately we get all errors about misused structure in components and functions.

Refactoring superpowers!

6. I just started to learn javascript

Learning TypeScript will take you five extra minutes (I will share some tutorial later), but it will help you to see simple errors immediately and you can explore available typings with a library provided by the community. Therefore, you will spend more time by doing things, rather than chasing bugs.

If any of the statement above correlates with the case you have — you SHOULD USE TypeScript.

When to avoid using TypeScript — and why?

1. Hackathons

TypeScript is helpful in certain projects, but it can be quite painful in others. If we want to develop something extremely fast and don’t want to/don’t have time to set up everything properly — it is better to avoid Typings. Hackathons are special types of projects, when people collaborate with each other and want to close certain idea fast, so there is no time to set up or teach people how to use new technology.

2. Pet Projects

Every time you create your own pet project it is usually a small application that only you work on. As long as this app is not a way for you to learn TypeScript — you don’t need to add it to your project.

3. Test ideas

There are also situations when you have a quick idea on how to approach certain topic and you want to quickly test if it works. If this is the case — you don’t need to make your small test over complicated by adding static typing there.