Learning TypeScript – To “Type” or not to “Type”?


Two years ago I attended a very good talk about using TypeScript and CoffeeScript to generate your JavaScript code. At the time I had barely even written any JavaScript so even though the talk was very interesting and the tools were awesome I decided to wait until I was more comfortable with JavaScript.

Fast forward to now, I have a good year of experience with the MEAN stack which means I have a much better feel for the JS language. I have enough experience that I know I miss the static typing that C# provides me when I’m not working on a MEAN application. In case you were’t aware I’m a .Net Developer by day and a JS developer by night.

The tools

As I went through the TypeScript tutorial on TypeScriptLang.org I noticed there was an npm package for installing the TypeScript compiler (tsc.exe).

The compiler

npm install -g typscript

Definitely Typed d.ts files

One of the most beneficial features of TypeScript is the Type definition files. You can check them out at DefinitelyTyped.org along with a tool to install them very easily from the command line. The tool I’m talking about is called tsd. Stay tuned for a quick start guide to tsd.

The editor

My three favorite editors for JavaScript our Atom, WebStorm, and now Visual Studio Code.The best news is that each one of these tools has excellent TypeScript support. The new comer here is Visual Studio Code, but it is gaining a lot of traction in the developer community. And guess what, VS Code was written in TypeScript.

The test app

So after a few tutorials I decide that I need to start learning TypeScript by writing an Angular App. You can find this very simple app on GitHub. The application includes the following Angular features implemented with TypeScript:

  • Controllers
  • Services
  • Routing

Still to come on this repo is a TypeScript directive and unit tests. And don’t worry I plan to rewrite the API in Node

The verdict

After writing the Todo App, I’ve decided that learning TypeScript was a great idea. The main benefits I saw were with the excellent intellisense when using the Angular libraries and even my own classes. Additionally the support for ES6 classes and modules makes it very nice as well.