AngularJS in TypeScript: Introduction

Currently I'm building a website. And, obviously, I use AngularJS. However, this time I want to try something interesting. What if I write AngularJS in TypeScript?

There are a few reasons why I want to try to write using TypeScript:

  1. I've tried writing AngularJS using CoffeeScript on one of my project. The codes is much shorter and simpler. But to be honest, for someone who is still a beginner with CoffeeScript, I find it so hard. CoffeeScript is not compatible with JavaScript, so I need to keep using js2coffee to do conversion.
    TypeScript is different. It's like a superset of JavaScript, which means I can put pure JavaScript code and it will still compile correctly. For me, this is a plus thing because I can learn TypeScript while still working on my project. If I haven't found a proper way to write some codes in TypeScript, I'll just put the JavaScript version, then refactor later.

  2. I use Visual Studio almost every time I code, and it is very helpful when writing TypeScript, especially when WebEssentials is also installed. The intellisense and auto-syntax checking have made writing TypeScript much easier

  3. When writing JavaScript, I often do it in "Spaghetti" mode, which means the code is all over the place and not structured. I want to learn how to write a proper and well-structured JavaScript code. And I think writing in TypeScript will make my code better.

There are quite a few existing articles and tutorials on how to do this. One of them is article from DotNetCurry.

I follow that article with some modifications that I think will make the code more readable. I open-source this project so that I could share how I write AngularJS in TypeScript. The code is available here.

I'll share how I structure the code in later posts. Meanwhile, feel free to look at the repo above

Abdurrachman Habibi

Read more posts by this author.