简体   繁体   中英

How do I upgrade typescript in Visual Studio Code version 1.9.1

I received a message

Version mismatch! global tsc (2.0.2) != VS Code's language service (2.1.6). Inconsist

I Googled it and tried what was suggested but the problem remains. Please help

Version mismatch between tsc compiler and VS Code's language service

This error just means that the version of the TypeScript compiler ( tsc ) you have installed for command line compiling does not match the version of TypeScript that VSCode uses for Intellisense. This may result in VSCode showing or not show showing errors in the editor compared to what tsc would show when it is used to compile the same code.

If you are only working in JS, don't worry about this error. I've disabled it for JS projects in VSCode 1.10

Two possible fixes for TypeScript projects:

Update your global tsc install

npm install -g typescript@2.2.1

Also make sure tsc on the command line points to the path of the newly installed version of TypeScript.

Use a local Version of TypeScript for VSCode Language Features

Install TypeScript locally:

npm install --save-dev typescript@2.2.1

and update your workspace settings to use this version of typescript in VSCode:

{
  "typescript.tsdk": "./node_modules/typescript/lib"
}

Here are the complete instructions for configuring a local version of TypeScript: https://code.visualstudio.com/Docs/languages/typescript#_using-newer-typescript-versions


Update March 6, 2017

Use TS 2.2.1 instead of 2.1.6 in example

the source of this problem and another approach in my answer in another thread:

Version mismatch between tsc compiler and VS Code's language service

The global installed version of type script is not the one that came with Visual Studio Code. This impacts the debugger , editor etc, not the actual running of the code.

In Visual Studio Code you can update the user settings to override the installed settings of Visual Studio Code.

So assuming you used Npm to install type script and that version is newer or different, you can use the same version inside Visual Studio Code. There are project based or system based ways to do this. I found the easiest is to add this to the user specific settings.

This is done easily inside Visual Studio Code.

Open Visual Studio Code GUI, open the Files Menu then Preferences Menu and User Settings.

Add this setting to the user settings:

{ "typescript.tsdk": "C:\\Users\\userName\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib" }

This is for windows.

More complete instructions here for other operating systems: Use Specific Version of TypeScript with VS Code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM