如何自动将TypeScript转换为JavaScript?

时间:2016-06-23 17:10:20

标签: javascript angularjs typescript

我正在通过阅读2015年的书ng-book2来学习angularjs2,但是它已经停止使用tsc将动态类型脚本转换为javascript的节点包已弃用:

  

npm WARN弃用了tsd@0.6.5:不推荐使用TSD,而是选择打字   (https://github.com/typings/typings) - 见   https://github.com/DefinitelyTyped/tsd/issues/269了解更多信息

。我对其他教程有其他方法,我想知道是否就如何最好地在开发机器上进行交流达成共识?

这是我使用的package.json:

{
  "name": "ng-book2-reddit",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "clean": "rm -f ./*.js; rm -f ./*.js.map; rm -f ./intermediates/*.js; rm -f ./intermediates/*.js.map",
    "tsc": "./node_modules/.bin/tsc",
    "tsc:w": "./node_modules/.bin/tsc -w",
    "serve": "./node_modules/.bin/live-server --host=localhost --port=8080 .",
    "go": "concurrent \"npm run tsc:w\" \"npm run serve\" "
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common": "2.0.0-rc.1",
    "@angular/compiler": "2.0.0-rc.1",
    "@angular/core": "2.0.0-rc.1",
    "@angular/http": "2.0.0-rc.1",
    "@angular/platform-browser": "2.0.0-rc.1",
    "@angular/platform-browser-dynamic": "2.0.0-rc.1",
    "@angular/router": "2.0.0-rc.1",
    "core-js": "2.2.2",
    "es6-shim": "^0.35.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "^0.19.6",
    "ts-helpers": "1.1.1",
    "tslint": "3.7.0-dev.2",
    "typescript": "1.9.0-dev.20160409",
    "typings": "^0.8.1",
    "zone.js": "0.6.12"
  },
  "devDependencies": {
    "concurrently": "1.0.0",
    "live-server": "0.9.0",
    "typescript": "1.7.3"
  }
}

2 个答案:

答案 0 :(得分:2)

<强>更新 tsd已被弃用,而不是tsc。

<button class="download-button">Download</button>用于安装TypeScript类型定义,并已替换为tsd

typings是TypeScript编译器。

使用以下命令全局安装tsc命令行实用程序:

typings

有关使用typings的更多说明,请参阅此处。

安装Mocha TypeScript类型定义的示例:

npm install typings --global

你可以在你的packages.json中使用脚本:

typings install dt~mocha --global --save

您应该创建 "tsc": "tsc", see here for an example

然后在你的shell中运行:

tsconfig.json

npm run tsctypescript中还有dependencies个软件包,您只需要devDependencies

答案 1 :(得分:1)

在这种情况下使用

npm run tsc:w

package.json

  

“tsc:w”:“。/ node_modules / .bin / tsc -w”,