k0p*_*kus 3 tsc typescript-typings typescript2.0
我已经使用打字稿启动了一个新的节点项目。
我通过以下方式安装了打字稿:
$ npm install typescript@2 -g
Run Code Online (Sandbox Code Playgroud)
我的环境是这样的:
$ tsc -v
Version 2.0.0
$ node -v
v7.10.0
Run Code Online (Sandbox Code Playgroud)
我通过以下方式安装了节点的类型:
npm install --save @types/node
Run Code Online (Sandbox Code Playgroud)
我希望:
tsc
Run Code Online (Sandbox Code Playgroud)
只是没有错误地运行。相反,我收到了关于打字本身的错误:
366 isTTY?: true;
~~~~
node_modules/@types/node/index.d.ts(366,17): error TS1110: Type expected.
1907 all?: false;
~~~~~
node_modules/@types/node/index.d.ts(1907,15): error TS1110: Type expected.
1911 all: true;
~~~~
node_modules/@types/node/index.d.ts(1911,14): error TS1110: Type expected.
1930 ttl: true;
~~~~
node_modules/@types/node/index.d.ts(1930,14): error TS1110: Type expected.
4138 type DoesZapCodeSpaceFlag = 0 | 1;
~
node_modules/@types/node/index.d.ts(4138,33): error TS1110: Type expected.
Run Code Online (Sandbox Code Playgroud)
我的打字稿无论如何都会转译,但我宁愿修复这些错误。如何修复它们?
我使用的是过时的 tsc 版本。您可以通过以下方式检查这是否是问题:
$ which tsc
/usr/local/bin/tsc
Run Code Online (Sandbox Code Playgroud)
并且它没有被“npm install typescript -g”更新,因为它们被安装到了相对于我的 nvm 的路径。
相反,我现在通过以下方式为项目使用本地版本的打字稿:
npm install typescript --save
Run Code Online (Sandbox Code Playgroud)
将可执行文件存储到:
$ ./node_modules/typescript/bin/tsc -v
Version 2.3.2
Run Code Online (Sandbox Code Playgroud)
npm 脚本默认查找本地二进制文件,因此我在 package.json 中添加了脚本:
"scripts": {
"console": "tsc && node dist/console.js",
},
Run Code Online (Sandbox Code Playgroud)
所以我可以运行:
npm run console
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1243 次 |
| 最近记录: |