A question that repeatedly comes up for me as I join a new team and project — should we adopt TypeScript? Let’s look at the pros and cons.
“Should we adopt TypeScript?”
As TypeScript further grows in popularity, it is a question that repeatedly comes up for me as I join a new project where the tools and tech are selected from scratch. So, here is an up to date top level, and more in-depth look at the benefits and drawbacks of adopting TypeScript in your project.
- Better integration with text editors
- Types help self document the code
- It is faster to refactor
- Catches bugs before compilation
- Can compile down to a target ES version
- Get early access to future features of JS
- Unit tests are no longer instant
- Compilation time is increased
- Build pipelines take longer
- A smaller pool of developers to hire
- Non-TS libraries require types
- Pinning version types to get a working compile
- Typescript is full of quirks that are confusing
- Types are only checked at compile time
- Does not reduce bug density
- Leaving the community-driven JS path for Microsoft lock-in
- Dynamic types are actually useful
- More code needs to be written
- Poor and incomprehensible errors
Better integration with text editors (benefit)
Once TypeScript is set up, there are plugins available for most popular text editors. Visual Studio Code, Atom, Webstorm, etc. The images below are from Microsoft’s Typescript installation tutorial. In the first image, we can see all the available console methods in the IntelliSense modal, now annotated with types to help you select the correct method. The second image shows parameter help when calling a function, it shows the parameter types that are required, and ones that are optional. Neat!