javascript - Angular JS 2.0 将 typescript 编译为 javascript

标签 javascript angularjs npm reddit typescript1.5

我刚刚在 the Poor Mans reddit 上试用 AngularJS 2.0。我有以下脚本,称为 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)

但是,保存后,我想将其编译为javascript(js文件) 我认为使用 tsc app.ts 应该可以工作,但是编译器会向命令行输出许多错误。

我已经通过 npm install -g 'typescript@^1.5.0-beta' 安装了 tsc 并运行了 npm install。我得到的错误大致如下:

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.

任何人都可以阐明我在这里做错了什么吗?

谢谢...

最佳答案

您需要向编译器提供几个参数才能使其工作。

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

还要确保您从definitelytyped 存储库中获得了正确的 typescript 定义文件。

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

关于javascript - Angular JS 2.0 将 typescript 编译为 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31292020/

相关文章:

javascript - js中获取输入类型text的值

Javascript 只触发一次

JavaScript:将对象存储为固定值?

javascript - AngularJS:ng-click 在 ui-grid cellTemplate 中不起作用

javascript - AngularJS,将更改从工厂应用到 View

javascript - 'gulp-jade' 无法正常工作或无法将 jade 编译为 html

javascript - 从对象列表中过滤($filter)匹配值,排除不必要的属性

node.js - 无法在Windows 8.1上安装zombiejs

javascript - 是否可以在同一个盒子上安装多个 framework7?

javascript - Laravel Vue.js 应用程序未运行