如何将 Typescript 升级到最新版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15301451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to upgrade Typescript to the latest version?
提问by Cesco
I have a MacBook Pro with OS X 10.8.2 Some time ago I installed Typescript and today I'd like to upgrade that installation to the latest version available (so far, v0.8.3). I wrote this command from the terminal:
我有一台装有 OS X 10.8.2 的 MacBook Pro 前段时间我安装了 Typescript,今天我想将该安装升级到可用的最新版本(到目前为止,v0.8.3)。我从终端写了这个命令:
sudo npm install -g typescript
But this is what I got on the display:
但这是我在显示器上看到的:
npm http GET https://registry.npmjs.org/typescript
npm http 304 https://registry.npmjs.org/typescript
/usr/local/bin/tsc -> /usr/local/lib/node_modules/typescript/bin/tsc
[email protected] /usr/local/lib/node_modules/typescript
Does this means that I still have version 0.8.0 installed on my computer?
I tried to see if the tsc command has a -v
or a -version
parameter but I haven't found it, so I still uncertain if I have upgraded Typescript to the latest release or if I'm still stuck with an older version.
这是否意味着我的计算机上仍然安装了 0.8.0 版?我试图查看 tsc 命令是否有一个-v
或一个-version
参数,但我没有找到它,所以我仍然不确定我是否已将 Typescript 升级到最新版本,或者我是否仍然坚持使用旧版本。
采纳答案by Cesco
I just realised that I was using an old version of npm. I have upgraded npm to the latest version, then re-installed typescript and now I have the latest version of typescript installed on my computer.
我刚刚意识到我使用的是旧版本的 npm。我已将 npm 升级到最新版本,然后重新安装了 typescript,现在我的计算机上安装了最新版本的 typescript。
回答by BenR
Since selected correct answer didn't help me I figured I'd share how I resolved the issue.
由于选择的正确答案对我没有帮助,我想我会分享我是如何解决这个问题的。
I had to remove C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
from my PATH.
我不得不C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
从我的路径中删除。
After that I could run this command and see the version I was expecting:
之后,我可以运行此命令并查看我期望的版本:
C:\>tsc --version
message TS6029: Version 1.5.3
回答by Puneeth Rai
I had the same problem below procedure worked for me
我在下面的过程中遇到了同样的问题对我有用
Update NPM
更新 NPM
npm install npm@latest -g
Update typescript
更新打字稿
npm -g upgrade typescript
or
或者
npm install typescript@latest -g
now you should see
现在你应该看到
tsc --version
Version 2.1.5
版本 2.1.5
回答by vezenkov
For those still struggling with that - try running WHERE tsc
in Command Prompt or Node.js Command Prompt and you'll get all the locations it is installed. Remove the excessive location from PATH env var.
对于那些仍在为此苦苦挣扎的人 - 尝试WHERE tsc
在命令提示符或 Node.js 命令提示符中运行,您将获得它安装的所有位置。从 PATH env var 中删除过多的位置。
回答by WonderHeart
Even when i installed latest typescript, still i was getting version as 1.0.3 when doing tsc -v
即使我安装了最新的打字稿,在执行 tsc -v 时我仍然获得 1.0.3 版本
The corrected answer didn't help me , but followed @BenR approach, removed this PATH C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\ from System Variables
更正的答案对我没有帮助,但遵循@BenR 方法,从系统变量中删除了此 PATH C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
and then opened new windows command prompt and then typed
然后打开新的 Windows 命令提示符,然后键入
tsc -v
Version 2.3.3
So now i was able to compile the typescript files using tsc file.ts
所以现在我能够使用编译打字稿文件 tsc file.ts
Hope this helps someone.
希望这可以帮助某人。
回答by Legends
Open a command line tool cmd.exe/Git Bash
and execute:
打开命令行工具cmd.exe/Git Bash
并执行:
npm install -g typescript@latest
The command will do the following:
该命令将执行以下操作:
Check if Typescript is installed and ..
检查是否安装了 Typescript 并且..
- if installed already, updateit to the latest version
- if not installed, installthe latest version
- 如果已经安装,请更新到最新版本
- 如果没有安装,请安装最新版本
It has been reported that the following command will not work reliably when you already have typescript installed:
据报道,当您已经安装了 typescript 时,以下命令将无法可靠运行:
npm update -g typescript@latest
Test the versionusing
测试版本使用
tsc -v // prints out the locally installed typescript version
Furthermore you can check, which is the latest available version for typescript in the npm registry:
此外,您可以检查npm 注册表中打字稿的最新可用版本:
npm view typescript version // prints the latest available version in the npm registry
回答by Heather Roberts
I had the same problem on Linux, possibly related to using node version manager.
我在 Linux 上遇到了同样的问题,可能与使用节点版本管理器有关。
I fixed it by finding where tsc was and then manually going in and deleting those folders
我通过找到 tsc 的位置然后手动进入并删除这些文件夹来修复它
$ which tsc
/home/vagrant/.nvm/versions/node/v6.9.5/bin/tsc
$ cd /home/vagrant/.nvm/versions/node/v6.9.5/bin/
$ ll
...
lrwxrwxrwx 1 vagrant vagrant 38 Nov 30 10:32 tsc -> ../lib/node_modules/typescript/bin/tsc*
lrwxrwxrwx 1 vagrant vagrant 43 Nov 30 10:32 tsserver -> ../lib/node_modules/typescript/bin/tsserver*
...
$ rm -rf ../lib/node_modules/typescript/ tsc tsserver
回答by Sunny
- I had Visual Studio installed on my Windows OS computer, which added its own version of TypeScript installation into the System Path
- Uninstalled 'TypeScript for Visual Studio' from Programs and Features
- Installed latest typescript. From command prompt 'npm install -g typescript@latest'
- Issue solved!
- 我在 Windows 操作系统计算机上安装了 Visual Studio,它将自己的 TypeScript 安装版本添加到系统路径中
- 从程序和功能中卸载“TypeScript for Visual Studio”
- 安装了最新的打字稿。从命令提示符'npm install -g typescript@latest'
- 问题解决了!
I know this is an old Question, but I faced a similar issue and none of the answers here solved it, posting my answer for anyone else in the same boat.
我知道这是一个老问题,但我遇到了类似的问题,这里的答案都没有解决它,将我的答案发布给同一条船上的其他人。
回答by godblessstrawberry
I just faced this issue on the windows 8 machine with blocked admin access where I was unable to uninstall global typescript, modify PATH
etc.
我刚刚在 Windows 8 机器上遇到了这个问题,管理员访问被阻止,我无法卸载全局打字稿,修改PATH
等。
Here's how to launch typescript projects in this case:
以下是在这种情况下启动打字稿项目的方法:
- install local typescript version for project
npm install typescript@latest
( avoid-g
param) add build scripts to
package.json
e.g.scripts: { "clean": "rimraf coverage build tmp", "build": "tsc -p tsconfig.release.json", "build:watch": "tsc -w -p tsconfig.release.json", "lint": "tslint -t stylish --project \"tsconfig.json\"", "test": "jest --coverage", "test:watch": "jest --watch" }
run typescript compiler with the local version of typescript via
npm run build:watch
which will launchtsc -w -p tsconfig.release.json
using project's localtsc
fromnode_modules
- 为项目安装本地打字稿版本
npm install typescript@latest
(避免-g
参数) 将构建脚本添加到
package.json
例如scripts: { "clean": "rimraf coverage build tmp", "build": "tsc -p tsconfig.release.json", "build:watch": "tsc -w -p tsconfig.release.json", "lint": "tslint -t stylish --project \"tsconfig.json\"", "test": "jest --coverage", "test:watch": "jest --watch" }
运行带有打字稿的本地版本打字稿编译通过
npm run build:watch
,将推出tsc -w -p tsconfig.release.json
使用项目的本地tsc
从node_modules
回答by Adam Weber
I encountered the same issue and none of the popular answers resolved the problem for me. I'm on Windows 10 with Visual Studio 2017.
我遇到了同样的问题,但没有一个流行的答案为我解决了这个问题。我在 Windows 10 上使用 Visual Studio 2017。
I tried using where tsc
from the console to determine where the path to tsc
was resolving. The first entry was similar to: C:\Program Files (x86)\Microsoft SDKs\TypeScript\x.xx
. So I checked the PATH
variable (both System and User) and that path was nowhere to be found.
我尝试where tsc
从控制台使用来确定tsc
解析路径的位置。第一个条目类似于:C:\Program Files (x86)\Microsoft SDKs\TypeScript\x.xx
。所以我检查了PATH
变量(系统和用户)并且找不到那个路径。
I finally stumbled across this comment on GitHub: https://github.com/Microsoft/TypeScript/issues/4971#issuecomment-144184935
我终于在 GitHub 上偶然发现了这条评论:https: //github.com/Microsoft/TypeScript/issues/4971#issuecomment-144184935
Which pointed me in the right direction. I use Console2
and my default console tab spawns a Visual Studio-enhanced console via this .bat
file:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat
这为我指明了正确的方向。我使用Console2
并且我的默认控制台选项卡通过此.bat
文件生成了一个 Visual Studio 增强的控制台:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat
That .bat
file doesn't contain anything TypeScript-specific, but it does run all the .bat
files found in C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\vsdevcmd\ext
. And one of thosefiles is conspicuously named typescript.bat
. I simply renamed that filed to some other extension, then re-opened a console and now everything is great.
这.bat
文件不包含打字稿特定的东西,但它并运行所有.bat
找到的文件C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\vsdevcmd\ext
。和一个这些文件被命名为明显typescript.bat
。我只是将其重命名为其他扩展名,然后重新打开控制台,现在一切都很好。
Not sure if this will bork up anything in Visual Studio, but I don't use it for TypeScript. And I suspect a future Visual Studio update may put that file back in place. But it works for now.
不确定这是否会破坏 Visual Studio 中的任何内容,但我不将它用于 TypeScript。我怀疑未来的 Visual Studio 更新可能会将该文件放回原处。但它现在有效。