Search code examples
javascriptangularjsnpmreddittypescript1.5

Angular JS 2.0 compiling typescript into javascript


I am just trialling AngularJS 2.0 with the poor mans reddit. I have the following script which is called app.ts

///<reference path="typings/angular2/angular2.d.ts" />

import {
    Component,
    View,
    bootstrap,
} from "angular2/angular2";

@Component({
    selector: 'hello world'
})
@View(
    { template: `<div>HelloWorld</div>` })
class HelloWorld {
}
bootstrap(HelloWorld)

However, after saving this, I'd like to compile it into javascript (js file) Using tsc app.ts I think should work, but the compiler spits out a number of errors to the command line.

I have installed the tsc via npm install -g 'typescript@^1.5.0-beta' and ran npm install. The errors I get are along the lines of:

C:\angular2-reddit\typings\angular2\angular2.d.ts(7,22): error TS1005: ')' expec
ted.
C:\angular2-reddit\typings\angular2\angular2.d.ts(14,6): error TS1008: Unexpecte
d token; 'module, class, interface, enum, import or statement' expected.

Can anyone shed any light on what I am doing wrong here?

Thanks...


Solution

  • You need to provide a couple of parameters to the compiler for it to work.

    > tsc.cmd -m commonjs -t es5 --emitDecoratorMetadata app.ts
    

    Also make sure you have the proper typescript definition files from the definitelytyped repo.

    > npm install -g tsd@^0.6.0
    > tsd install angular2 es6-promise rx rx-lite