【发布时间】:2016-08-13 17:25:30
【问题描述】:
npm 已安装并正在从 IntelliJ IDEA 15 中积极使用
我的目标是在 IntelliJ 中为我的 TypeScript 源代码生成类型,但我想学习使用 Windows 命令行,因此我可以显式指定命令行选项来修补以了解每个选项的作用。我对通过谷歌搜索找到的与设置和使用它相关的各种花絮感到困惑......我确信我错过了一些非常基本的东西,那些博客或回答问题的人认为这是常识...... .
这是我尝试过的以及我看到的......
第 1 步:安装 typescript:
npm install -g typescript
这会在我的系统上安装以下文件/目录结构:
C:\Users\{my user id}\AppData\Roaming\npm\node_modules\typescript
|---bin
| |--- tsc
| |--- tscserver
|---lib
| |--- lib.core.d.ts
| |--- ...
| |--- typescriptServices.js
|--- .npmignore
|--- ...
|--- ThirdPartyNoticeText.txt
第 2 步:天真地尝试直接从 Windows 命令行运行 tsc:
我通过谷歌搜索找到的示例采用以下形式:
编译单个文件:
tsc app.ts
以上示例来自http://www.primordialcode.com/blog/post/typescript-command-line-compiler
这不起作用,因为:
tsc的安装目录不在 WindowsPathC:\Users\{my user id}\AppData\Roaming\npm\node_modules\typescript\bin,显然这很容易通过更改 Window PATH 环境变量和/或输入要执行的命令时完全限定tsc文件的路径。更重要的是,
tsc文件不是 Windows 可执行文件...#!Unix 脚本 (shebang) 是一个死的赠品。
检查tsc 文件:
#!/usr/bin/env node
require('../lib/tsc.js')
第 3 步:尝试从节点命令提示符运行tsc:
C:\>node
> tsc
ReferenceError: tsc is not defined
at repl:1:1
at REPLServer.defaultEval (repl.js:252:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
^C
好的...让我们指定tsc 脚本的完整路径:
C:\>node
> C:\Users\{my user id}\AppData\Roaming\npm\node_modules\typescript\bin\tsc
...
字面上唯一的输出是 ... 在指定 tsc 脚本的完整路径时...我猜它需要参数...但是点击 tab 键会显示似乎是 node 命令的列表(不是 tsc 命令)...所以我不知道这里发生了什么...
现在我被卡住了
调用tsc需要安装/配置/使用什么环境(如图:http://www.primordialcode.com/blog/post/typescript-command-line-compiler)?
和/或
是否有教程或网站可以帮助我从一个干净的 Windows 系统转到能够从命令行使用 TypeScript 编译器为我的 TypeScript 源文件生成类型?
【问题讨论】:
标签: node.js windows typescript