简体   繁体   English

如何在Visual Studio Code 1.9.1版中升级打字稿

[英]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). 全局tsc(2.0.2)!= VS代码的语言服务(2.1.6)。 Inconsist 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 TSC编译器和VS Code的语言服务之间的版本不匹配

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. 此错误仅表示您为命令行编译安装的TypeScript编译器( tsc )版本与VSCode用于Intellisense的TypeScript版本不匹配。 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. 与使用tsc编译同一代码时所显示的内容相比,这可能导致VSCode在编辑器中显示或不显示错误。

If you are only working in JS, don't worry about this error. 如果您仅使用JS工作,则不必担心此错误。 I've disabled it for JS projects in VSCode 1.10 我已在VSCode 1.10中的JS项目中禁用了它

Two possible fixes for TypeScript projects: TypeScript项目的两个可能的修复:

Update your global tsc install 更新您的全局tsc安装

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. 还要确保命令行上的tsc指向新安装的TypeScript版本的路径。

Use a local Version of TypeScript for VSCode Language Features 将TypeScript的本地版本用于VSCode语言功能

Install TypeScript locally: 在本地安装TypeScript:

npm install --save-dev typescript@2.2.1

and update your workspace settings to use this version of typescript in VSCode: 并更新您的工作区设置以在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 以下是配置TypeScript本地版本的完整说明: https : //code.visualstudio.com/Docs/languages/typescript#_using-newer-typescript-versions


Update March 6, 2017 更新2017年3月6日

Use TS 2.2.1 instead of 2.1.6 in example 在示例中使用TS 2.2.1代替2.1.6

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 TSC编译器和VS Code的语言服务之间的版本不匹配

The global installed version of type script is not the one that came with Visual Studio Code. 类型脚本的全局安装版本不是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. 在Visual Studio Code中,您可以更新用户设置以覆盖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. 因此,假设您使用Npm来安装类型脚本,并且该版本是新的或不同的,则可以在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. 在Visual Studio Code中可以轻松完成此操作。

Open Visual Studio Code GUI, open the Files Menu then Preferences Menu and User Settings. 打开Visual Studio Code GUI,打开“文件”菜单,然后打开“首选项”菜单和“用户设置”。

Add this setting to the user settings: 将此设置添加到用户设置:

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

This is for windows. 这是用于Windows。

More complete instructions here for other operating systems: Use Specific Version of TypeScript with VS Code 其他操作系统的详细说明请参见将特定版本的TypeScript与VS Code结合使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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