TypeScript has not taken much ground in the AngularJS community yet. Here’s a small tutorial on how to write directives in TypeScript.
We’re currently building a UI that has multiple independent sections. For each of them, we will write a directive that handles everything on its own.
With that in mind, here’s a simple TypeScript directive for AngularJS.
Then, it can be used in a view as such:
Those a little less familiar with AngularJS directives will need to understand that when declaring it, the scope value declares which
attributes can be passed to that directive.
Declaring the Customer in the ISomeScope interface is very practical since it’s now explicit what this controller needs. It also makes for easier testing.