如何使用 npm 将 TypeScript 更新到最新版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39677437/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:21:09  来源:igfitidea点击:

How to update TypeScript to latest version with npm?

typescriptnpmnpm-install

提问by blueMoon

Currently I have TypeScript 1.0.3.0 version installed on my machine.
I want to update it to latest one i.e. 2.0.

目前我的机器上安装了 TypeScript 1.0.3.0 版本。
我想将其更新到最新版本,即 2.0。

How to do this with npm?

如何用 npm 做到这一点?

回答by eavidan

Try npm install -g typescript@latest. You can also use npm updateinstead of install, without the latest modifier.

试试npm install -g typescript@latest。您也可以使用npm update代替安装,而无需最新的修饰符。

回答by Legends

Open command prompt (cmd.exe/git bash)

打开命令提示符 (cmd.exe/git bash)

Recommended:

受到推崇的:

npm install -g typescript@latest

or

或者

yarn global add typescript@latest  // if you use yarn package manager

This will install the latest typescript version if not already installed, otherwise it will updatethe current installation to the latest version.

如果尚未安装,这将安装最新的打字稿版本, 否则会将当前安装更新为最新版本。

And then verifywhich version is installed:

然后验证安装了哪个版本:

tsc -v

enter image description here

在此处输入图片说明



If you have typescript already installed you could also use the following command to update to latest version, but as commentators have reported and I confirm it that the following command does not update to latest (as of now [Feb 10 '17])!

如果您已经安装了 typescript,您还可以使用以下命令更新到最新版本,但正如评论员所报告的那样,我确认以下命令不会更新到最新版本(截至目前 [ Feb 10 '17])!

npm update -g typescript@latest

回答by Veener

If you are on Windows and have Visual Studio installed you might have something in your PATH that is pointing to an old version of TypeScript. I found that removing the folder "C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\" from my PATH (or deleting/renaming this folder) will allow the more recent npm globally installed TypeScript version of tsc to work.

如果您使用的是 Windows 并安装了 Visual Studio,则您的 PATH 中可能有指向旧版本 TypeScript 的内容。我发现从我的 PATH 中删除文件夹“C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\”(或删除/重命名此文件夹)将允许更新的 npm 全局安装的 TypeScript 版本的 tsc 工作。

回答by Andrew Reid

You should be able to do this by simply typing npm install -g [email protected]. If this does not work, I am beginning to wonder what version of node and npm you are on. Try node -vand npm -vto find these out. You should be on node >4.5 and npm >3

您应该可以通过简单地输入npm install -g [email protected]. 如果这不起作用,我开始想知道您使用的是哪个版本的 node 和 npm。尝试node -vnpm -v找到这些了。您应该在 node >4.5 和 npm >3 上

回答by Pascal Tovohery

Just use the command # npm update -g typescript
For update all global installed module, Use this command# npm update -g

只需使用命令# npm update -g typescript
更新所有全局安装的模块,使用此命令# npm update -g

回答by Little Roys

For npm: you can run:

对于npm:您可以运行:

npm update -g typescript

By default, it will install latest version.

默认情况下,它将安装最新版本。

For yarn, you can run:

对于yarn,您可以运行:

yarn upgrade typescript

Or you can remove the orginal version, run yarn global remove typescript, and then execute yarn global add typescript, by default it will also install the latest version of typescript.

或者您可以删除原始版本,运行yarn global remove typescript,然后执行yarn global add typescript,默认情况下它还会安装最新版本的打字稿。

more details, you can read yarn docs.

更多细节,你可以阅读yarn docs

回答by Donato Szilagyi

If you are using Windows with very old NodeJS, then uninstall previous NodeJs and NVM (Node Version Manager) in Control Panel (Win7) or Settings/Apps (Win10) if exists. Make sure that they are removed from the PATH.

如果您在 Windows 上使用非常旧的 NodeJS,请在控制面板 (Win7) 或设置/应用程序 (Win10)(如果存在)中卸载以前的 NodeJs 和 NVM(节点版本管理器)。确保它们已从 PATH 中删除。

Reinstall NodeJS: https://nodejs.org/en/downloadIt will install NPM as well.

重新安装 NodeJS:https: //nodejs.org/en/download它也会安装 NPM。

Install TypeScript globally:

全局安装 TypeScript:

npm install -g typescript

Verify installation:

验证安装:

tsc -v

回答by impactro

Use command 'where' in prompt to find current executable in path

在提示中使用命令“where”在路径中查找当前可执行文件

C:\> where tsc
C:\Users\user\AppData\Roaming\npm\tsc
C:\Users\user\AppData\Roaming\npm\tsc.cmd