简体   繁体   English

TypeScript Visual Studio 2022 版本不匹配

[英]TypeScript version mismatch in Visual Studio 2022

With a web project set to use 4.4 explicitly via the Projet Properties, TypeScript Build:将 web 项目设置为通过 Projet Properties 明确使用 4.4,TypeScript 构建: 打字稿构建设置 Note that it says "unavailable".请注意,它说“不可用”。

I get this warning when opening the project with VS2022: PROJECT.X specifies TypeScript version 4.4, but a matching compiler was not found. Would you like us to update your project to use TypeScript 4.3?使用 VS2022 打开项目时收到此警告: PROJECT.X specifies TypeScript version 4.4, but a matching compiler was not found. Would you like us to update your project to use TypeScript 4.3? PROJECT.X specifies TypeScript version 4.4, but a matching compiler was not found. Would you like us to update your project to use TypeScript 4.3? 更新打字稿对话框

If I change the TypeScript version to "Use latest available":如果我将 TypeScript 版本更改为“使用最新可用”: 打字稿构建设置

On loading, the warning becomes: PROJECT.X is built using TypeScript 4.3, but the TypeScript language service version currently in use by Visual Studio is 4.4. This may be caused by other projects in the solution using a different version of TypeScript. Would you like us to update your project to use TypeScript 4.4?加载时,警告变为: PROJECT.X is built using TypeScript 4.3, but the TypeScript language service version currently in use by Visual Studio is 4.4. This may be caused by other projects in the solution using a different version of TypeScript. Would you like us to update your project to use TypeScript 4.4? PROJECT.X is built using TypeScript 4.3, but the TypeScript language service version currently in use by Visual Studio is 4.4. This may be caused by other projects in the solution using a different version of TypeScript. Would you like us to update your project to use TypeScript 4.4? 更新打字稿对话框

So these seem to say VS has a 4.4 language service, but not the matching compiler?所以这些好像是说 VS 有 4.4 语言服务,但是没有配套的编译器?

I have read:我读过了:

How do I get rid of these warnings?我如何摆脱这些警告?

A solution I found and hope it's working for you.我找到了一个解决方案,希望它对你有用。

First, run Visual Studio installer and click "Modify" on your version (sorry the screenshot is in french but it should be the same):首先,运行 Visual Studio 安装程序并在您的版本上单击“修改”(抱歉,屏幕截图是法语的,但应该是一样的): 在此处输入图像描述

Then go to the tab "individual components" and check "TypeScript 4.4 SDK Kit":然后 go 到“单个组件”选项卡并选中“TypeScript 4.4 SDK 套件”: 在此处输入图像描述

After doing that, the TypeScript version 4.4 became available on the Project Properties page.这样做之后,TypeScript 版本 4.4 在“项目属性”页面上可用。

However, the latest TypeScript version (4.5.x) doesn't seem to be available with that method.但是,最新的 TypeScript 版本 (4.5.x) 似乎不适用于该方法。

As hinted in https://stackoverflow.com/a/56681453/1948625 , one solution is to move $(PATH) higher up the list in Options, Projects and Solutions, Web Package Management, External Web Tools.正如https://stackoverflow.com/a/56681453/1948625中所暗示的,一种解决方案是将$(PATH)在选项、项目和解决方案、Web Package 管理、外部 Web 工具中的列表中移到更高的位置。

However, I think there's a bit more to it.但是,我认为还有更多内容。 The default is this:默认是这样的: 外部工具的位置

With that, I get the warnings above (one of them, depending the TypeScript Version 4.4 or Latest, on the web project properties).有了这个,我得到了上面的警告(其中之一,取决于 TypeScript 版本 4.4 或最新版本,在 web 项目属性上)。

If I uncheck or remove $(VSInstalledExternalTools) (rather than move PATH to the top), the warnings go away.如果我取消选中或删除$(VSInstalledExternalTools) (而不是将 PATH 移至顶部),则警告 go 消失。

Having removed $(VSInstalledExternalTools) , I now add a fake $(SomethingRandom) at the top of the list, the warnings come back.删除$(VSInstalledExternalTools)后,我现在在列表顶部添加一个假的$(SomethingRandom) ,警告又回来了。

As I posted here https://stackoverflow.com/a/71125529/1948625 I cannot find the value of $(VSInstalledExternalTools) .正如我在此处发布的那样 https://stackoverflow.com/a/71125529/1948625我找不到$(VSInstalledExternalTools)的值。 This makes me think it's undefined, just like $(SomethingRandom) .这让我觉得它是未定义的,就像$(SomethingRandom)一样。 I think there's possibly a bug here where locations of external tools doesn't cascade down the list as expected, maybe crashes out if one of the paths is invalid or blank.我认为这里可能存在一个错误,外部工具的位置没有按预期在列表中级联,如果其中一个路径无效或空白,可能会崩溃。

I still prefer to use the version of the current project, so I prefer .\node_modules\.bin at the top of the list, rather that $(PATH) .我仍然更喜欢使用当前项目的版本,所以我更喜欢列表顶部的.\node_modules\.bin ,而不是$(PATH) This is my solution to get rid of the warnings:这是我摆脱警告的解决方案: 外部工具的位置

To find all your TypeScript compilers versions, try running this powershell:要查找所有 TypeScript 编译器版本,请尝试运行此 powershell:

Get-Childitem –Path C:\,D:\ -Recurse -Force -Include tsc.cmd -ErrorAction SilentlyContinue | foreach { $_.FullName; & $_ -v }

this would help in reconciling the order of the locations above, whether these folders are in your Path variable, etc.这将有助于协调上述位置的顺序,这些文件夹是否在您的 Path 变量中等。

My output is something like this:我的 output 是这样的:

C:\Users\BobSMith\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\.bin\tsc.cmd
Version 4.1.6
C:\Users\BobSMith\AppData\Roaming\npm\tsc.cmd
Version 4.5.5
D:\$RECYCLE.BIN\S-1-12-1-732868070-XXX-XXX-XXX\$RH58AY6.1\src\XXX\XXX.Web\node_modules\.bin\tsc.cmd
Version 3.8.3
D:\code\XXX\XXX.Web\node_modules\.bin\tsc.cmd
Version 3.4.5
D:\code\YYY\YYY.Web\node_modules\.bin\tsc.cmd
Version 4.4.2
D:\code\XXX\ZZZ\node_modules\.bin\tsc.cmd
Version 4.2.4

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

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