如何将TypeScript自动转换为JavaScript?

如何将TypeScript自动转换为JavaScript?,javascript,angularjs,typescript,Javascript,Angularjs,Typescript,我通过阅读2015年的一本书来学习angularjs2,但它使用tsc将typescript动态转换为javascript的节点包已停止使用: npm警告已弃用tsd@0.6.5:TSD不赞成打字 ()-见 更多信息 。我在不同的教程上有其他的方法,但是我想知道对于如何最好地在开发机器上传输,是否有共识 下面是我使用的package.json: { "name": "ng-book2-reddit", "version": "1.0.0", "private": true, "s

我通过阅读2015年的一本书来学习angularjs2,但它使用
tsc
将typescript动态转换为javascript的节点包已停止使用:

npm警告已弃用tsd@0.6.5:TSD不赞成打字 ()-见 更多信息

。我在不同的教程上有其他的方法,但是我想知道对于如何最好地在开发机器上传输,是否有共识

下面是我使用的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"
  }
}
在这种情况下,请使用

npm run tsc:w
在您的
package.json中

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

更新: tsd已弃用,而不是tsc

tsd
用于安装TypeScript类型定义,并已被
打字取代

tsc
是类型脚本编译器

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

npm安装打字--全局

有关使用的更多说明,请参见此处

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

typings安装dt~mocha--global--save

您只需在脚本下的packages.json中包含以下内容:

    "tsc": "tsc",
您应该创建一个
tsconfig.json

然后在shell中运行:

npm运行tsc


devDependencies
devDependencies
中也有
typescript
包,您只需要在
devDependencies
中使用它,这取决于您的构建工具。他们每个人都有一个包来运行
tsc
(无论是在处理中还是在外)。@ssube请参考我的
package.json
,了解工具。如果你想从命令行运行
tsc
,我相信你需要全局安装它。如果您使用的是gulp或grunt,那么它们都有typescript模块。由于tsc已被弃用,难道没有其他简单的方法可以做到这一点吗?@Karlom tsc--Watch我的意思是,一些不使用tsc的方法。我不想依赖不推荐的软件包。从长远来看,这将是徒劳的。tsd已被弃用,而不是tsc。请看我的答案。@Karlom如果您对我推荐的下一个短期课程的终端非常不满意,请您详细说明如何调整我的代码以使用打字。您可能会发现这本在线书籍更为最新:按照您的说明,我得到以下错误: