【问题标题】:Angular JS 2.0 compiling typescript into javascriptAngular JS 2.0 将打字稿编译成 javascript
【发布时间】:2015-07-14 03:59:47
【问题描述】:

我只是在用可怜的 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.

谁能解释我在这里做错了什么?

谢谢...

【问题讨论】:

    标签: javascript angularjs npm reddit typescript1.5


    【解决方案1】:

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

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

    还要确保您拥有来自确定类型存储库的正确打字稿定义文件。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-07
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 2015-10-06
      • 1970-01-01
      • 2013-08-19
      相关资源
      最近更新 更多