我想安装typescript,所以我使用了下面的命令:

npm install -g typescript 

和测试TSC——版本,但它只是显示' TSC命令未找到'。我尝试了stackoverflow, github和其他网站中建议的许多方法。但这并不奏效。我怎么知道typescript被安装和它在哪里。

我的操作系统是Unix, OS X El Capitan 10.11.6 节点版本为4.4.3, NPM的版本是3.10.5


当前回答

我必须这样做:

npx tsc app.ts

其他回答

我在这方面遇到了麻烦,因为我不想全局安装typescript。我发现我必须向包中添加一个脚本。Json为我调用TSC。解决方案可以在这里找到- https://stackoverflow.com/a/41446584/6301243

我必须这样做:

npx tsc app.ts

Use:

npm rebuild typescript

这将在您的机器上重新构建tsc链接。

首先使用npm Install typescript命令安装typescript 或者npm install -g typescript[用于全局安装typescript],然后运行npx tsc——version检查typescript的版本,而不是tsc——version。

同样,运行任何typescript文件,只需运行npx tsc <filename>.ts 例如,对于一个名为hello的文件。t,执行NPX TSC hello.ts。

以上这些对我都没用。

我也试过这个,

yum install typescript 

能够千方百计地编译如下。不推荐,只是一个变通办法。

只要使用npm在本地安装,就像npm install typescript一样,并在node_module文件夹中验证,如果已经下载。然后跑,

./node_modules/typescript/bin/tsc  --help
./node_modules/typescript/bin/tsc  //this line actually runs and compile and generate the compiled file.