How to update TypeScript to latest version with npm?

。_饼干妹妹 提交于 2019-11-27 06:56:16

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

On Windows open command prompt (cmd.exe)

Recommended:

npm install -g typescript@latest

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

And then verify which version is installed:

tsc -v


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)!

npm update -g typescript@latest

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.

You should be able to do this by simply typing npm install -g typescript@2.0. If this does not work, I am beginning to wonder what version of node and npm you are on. Try node -v and npm -v to find these out. You should be on node >4.5 and npm >3

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

For npm: you can run:

npm update -g typescript

By default, it will install latest version.

For yarn, you can run:

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.

more details, you can read yarn docs.

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.

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

Install TypeScript globally:

npm install -g typescript

Verify installation:

tsc -v

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

C:\> where tsc
C:\Users\user\AppData\Roaming\npm\tsc
C:\Users\user\AppData\Roaming\npm\tsc.cmd
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!