Why You Should Give TypeScript A Go

Four years ago I went to a talk about TypeScript and while I thought it had some neat features, I didn’t really give it a chance. It seemed like a bit of hassle to get started and it is made by Microsoft, so I thought it wasn’t very cool and the project would probably die within a few years.

Recently a client said that they specifically wanted to use Angular 2 and therefore I had to learn and use TypeScript. I like it so much that I’ve converted my utility library Svelte to use it and here’s why.

It’s Modern!

TypeScript closely follows the ES2015 standard (on a side note Medium has rubbish numbers). For example, below I have created a simple Utils class with a method for reading cookies:

By using TypeScript you can use most of the cool new JavaScript features and it compiles it to ES5 or ES3 so that it can be used in older browsers. Obviously you could just use Babel (this example compiles fine using Babel), but when using modules I find Babel takes a little more setup than using TypeScript. You can also control how you want your modules to be outputted 'commonjs', 'amd', 'system', 'umd', 'es6', or 'es2015'.


Obviously one of it’s key points is types. So following on from the previous example above I have added a type for the name argument.

By adding the type using ':string' to the name argument, TypeScript will tell me when using the readCookie method that I need to pass in a string and it will error if I don’t give it a string. Cool!

Autocomplete and Tooling

Probably the best feature of TypeScript is the autocomplete IntelliSense or whatever you want to call it. It’s great for getting things done quickly, without having to read a libraries whole documentation.

It even has basic factoring like ‘rename a symbol’, which actually works a treat!

Angular 2 and React

It’s basically the only way to use Angular 2 and it works really well. There is an interesting article by one of the Angular 2 developers on why they choose TypeScript.

You can even use it with React, as it supports JSX.

Just give it a go:-)!

Frontend Web Developer

Frontend Web Developer