npm已安装并且正在从IntelliJ IDEA 15中积极使用。
我的目标是在IntelliJ中为我的TypeScript源代码生成类型定义文件,但我想要学习使用Windows命令行,以便可以显式指定tinker的命令行选项,以理解每个选项的作用。 我通过谷歌搜索找到了与此设置和使用相关的各种细节...我相信我错过了一些非常基本的东西,那些博客或回答问题的人都假定为常识...
下面是我尝试过的和我看到的内容...
步骤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
的安装目录不在Windows路径
C:\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\{我的用户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源文件的类型定义?