17

I am thoroughly confused by Typescript versioning as it relates to Visual Studio 2019. I have a .NET Core 2.2.x project which utilizes Typescript. When I edit any .ts file, I get the following warning (in the error list):

Your project is built using TypeScript 3.4, but the TypeScript language service version currently in use by Visual Studio is 3.4.3. Your project may be using TypeScript language features that will result in errors when compiling with this version of the TypeScript compiler. To remove this warning, install the TypeScript 3.4.3 SDK or update the TypeScript version in your project's properties.

It claims that my project is built using TypeScript 3.4, but package.json specifically lists "typescript": "3.4.3".

enter image description here

Then it asks to install TypeScript SDK 3.4.3, which I have from here. I also npm install -g typescript previously, so running tsc -v yields Version 3.4.3.

What am I missing?

AngryHacker
  • 59,598
  • 102
  • 325
  • 594

2 Answers2

16

I had a similar problem as you describe but in the Task Runner Explorer.

Assumptions: TypeScript is should be in your PATH variables (you can check by running 'tsc -v' from a normal command prompt.

Since quite a while, Visual Studio allows you to choose the TypeScript version to use on a per-project basis (right-click project => Properties => tab 'Typescript Build'). Here you could choose an officially installed version but also 'Use latest available'.

In Visual Studio Options you can specify the locations and order in which 'External Web Tools' are used when building web projects using 3rd party tools. In that list, you will probably find an item '$(PATH)'. I moved it to the top of the list, which makes the globally installed TypeScript version the first to be found when searching for it.

I hope this applies for your situation as well.

DotBert
  • 1,262
  • 2
  • 16
  • 29
  • `tsc` isn't in my `PATH` (either systemwide nor VS2019's Developer Command Line). The VS Errors List complains that my project is referencing TypeScript 3.9 when all of my projects' files actually reference TypeScript 4. I don't have the TypeScript VS extension nor TypeScript MSBuild NuGet package installed either. This is weird. – Dai Nov 11 '20 at 02:09
  • I posted a very, very similar issue (different warnings, and with VS2022), with a very, very similar answer here https://stackoverflow.com/questions/71126707/ : not moving `$(PATH)` to the top, but disabling `$(VSInstalledExternalTools)` instead. – Thierry_S Feb 15 '22 at 12:50
11

This may have gotten easier since the original answer.

Now you can just install NuGet package Microsoft.TypeScript.MSBuild.

Then you don't need to install the SDK separately and it is recommended by Microsoft to use NuGet or npm: https://learn.microsoft.com/en-us/visualstudio/javascript/javascript-in-vs-2019?view=vs-2019

In the project Properties > Typescript Build tab, the Typescript version will change to n.n (NuGet) and will be grayed out. Now if you work on a team, all team members will be certain to have the same version for this project! Cool!

Jess
  • 23,901
  • 21
  • 124
  • 145
  • 1
    thanks thanks thanks and thanks again - you have saved me from my pain and agony - let jess be blessed - here's my upvote. i have no clue how someone can implement it in such ridiculous ways like visual studio did. at least this works. – Stephan Schinkel Dec 03 '21 at 14:03