qsrzyq
Last Updated: February 25, 2016
·
6.62K
· richardmorgan

Getting Started with TypeScript & Angular

Install TypeScript and TypeScript Definition Manager

(obviously you'll need nodejs installed first)

npm install typescript -g
npm install tsd -g

Assume you have a file named 'myTypeScriptModule.ts' with the following code:

angular.module('someModule');

To transpile the TypeScript to JavaScript, simply run this command:

tsc myTypeScriptModule.ts

You will now get an error that TypeScript could not find symbol "angular".

This is where the TypeScript Definition manager comes into play.

In your typescript directory, create a new typescript project by running:

tsd init

Then install the definition file for angular:

tsd query angular --action install

This will download and create a new directory containing your angular definition file. Include it by updating your typescript file to point to the angular definition:

/// <reference path="angularjs/angular.d.ts" />
angular.module('someModule');

Try to transpile again, and it should generate the JS file without error:

tsc myTypeScriptModule.ts

They have a lot of other types as well:
https://github.com/DefinitelyTyped/tsd