也许这是显而易见的,但我到处检查(除了正确的地方),谷歌它。什么都没有。


当前回答

从Visual Studio 2022开始,Angular/React/Vue有了新的TypeScript/JavaScript项目类型,TypeScript SDK已弃用(但仍然可以通过VS安装程序安装,并带有警告),Visual Studio应该根据你的项目使用的TypeScript版本提供智能感知和语言支持(npm是通过包指定你正在使用的TypeScript版本的首选方式)。json文件)。

不过,根据这个答案,仍然有关于如何控制/辨别Visual Studio 2022在任何给定时刻支持哪种特定的TypeScript语言版本的问题。

其他回答

在这个问题被提出两年之后,使用Visual Studio命令提示符仍然没有为我提供正确的答案。但通常的帮助|关于窗口似乎工作这些天:

更新(2017年6月):

VS 2013没有显示这个信息。(稍后注意:VS 2017企业版也不显示此信息)。 VS使用Microsoft Build Engine (MSBuild)编译Typescript文件。MSBuild可以支持几个主要的Typescript版本,但是About窗口只显示最新的版本。

下面是深入了解问题的方法:

A.要检查Visual Studio/MSBuild安装了哪些版本的Typescript,请检查C:\Program Files (x86)\Microsoft sdk \ Typescript文件夹的内容。例如,我有1.0、1.8和2.2版本:

B.检查你的项目需要哪个版本的Typescript。在*。在csproj文件中,寻找<TypeScriptToolsVersion>标签,或者如果它没有,你可以添加它,就像这样

< PropertyGroup > ... < TypeScriptToolsVersion > 1。8 < / TypeScriptToolsVersion > ... < / PropertyGroup >

C.最后,你可以检查MSBuild实际使用的Typescript版本。在TOOLS |选项|项目和解决方案|构建和运行中将MSBuild项目输出详细信息设置为详细信息:

然后构建你的项目并检查输出:你应该看到(A)中描述的Typescript文件夹之一的引用。

TypeScript团队在Visual Studio 2017版本15.3及更高版本中整理了这个问题,包括免费的社区版。

如何查看Visual Studio中安装了哪些TypeScript版本

现在你所需要做的就是转到任何TypeScript Visual Studio项目的项目属性(在解决方案资源管理器/属性中右键单击项目文件),然后转到左侧的TypeScript Build选项卡。它有一个“Typescript version”下拉菜单,显示项目正在使用的版本,如果你打开它,下拉菜单会显示当前安装在Visual Studio中的所有版本的Typescript。

目前实际安装在C:\Program Files (x86)\Microsoft SDKs\TypeScript,然后是按版本号的子文件夹,至少在我电脑上的Win10上是这样。如果你想看到确切的版本(例如2.8.3而不仅仅是2.8),你可以在这里找到适当的tsc.exe,并查看它的属性(在文件资源管理器中右键单击/属性中的详细信息选项卡)。

如何安装特定的TypeScript版本

If you want to install a specific version of TypeScript then these can be found on Visual Studio Marketplace, although specific version numbers can be a little difficult to find in that list. A Google search for, for example, 'visual studio marketplace typescript 3.3.1' will usually find the exact version you want. If you install from here and restart Visual Studio the version will appear in the dropdown. Note also that some of the latest versions of TypeScript (e.g. 4.2) will refuse to install if there's a more recent version installed.

Node.js控制台应用程序

这个答案不适用于“Node.js控制台应用程序”项目类型,该项目属性中没有TypeScript Build选项卡。这是因为它使用了一个使用npm安装在项目文件夹中的TypeScript版本。版本可以在包中查看和更改。json文件,安装时出现在解决方案资源管理器的npm条目下,以及磁盘上的node_modules/typescript文件夹中。

As far as I understand VS has nothing to do with TS installed by NPM. (You may notice after you install TS using NPM, there is no tsc.exe file). VS targets only tsc.exe installed by TS for VS extension, which installes TS to c:\Program Files (x86)\Microsoft SDKs\TypeScript\X.Y. You may have multiple folders under c:\Program Files (x86)\Microsoft SDKs\TypeScript. Set TypeScriptToolsVersion to the highest version installed. In my case I had folders "1.0", "1.7", "1.8", so I set TypeScriptToolsVersion = 1.8, and if you run tsc - v inside that folder you will get 1.8.3 or something, however, when u run tsc outside that folder, it will use PATH variable pointing to TS version installed by NPM, which is in my case 1.8.10. I believe TS for VS will always be a little behind the latest version of TS you install using NPM. But as far as I understand, VS doesnt know anything about TS installed by NPM, it only targets whateve versions installed by TS for VS extensions, and the version specified in TypeScriptToolsVersion in your project file.

你可以做npm list | grep typescript,如果它是通过npm安装的。

如果你只为Visual Studio安装了TypeScript,那么:

启动Visual Studio命令提示符 输入tsc -v并按Enter


Visual Studio 2017版本15.3及以上将TypeScript版本绑定到单个项目,正如这个答案所指出的:

右键单击解决方案资源管理器中的项目节点 单击“属性” 进入TypeScript Build选项卡