I am using Visual Studio 2022 to work on an existing solution that contains a web project with a node app.
The app is configured in the package.json
file to use the TypeScript 3.8.3 npm package.
In a TypeScript file I am using the optional chaining syntax that should be supported since TypeScript version 3.7, yet the ide underlines it as an error "TS1109:Expression expected". Node version if that matters is 14.17.0. No Typescript version is installed globally.
This page states that
By default, Visual Studio 2022 provides language support for JavaScript and TypeScript files to power IntelliSense without any specific project configuration.
For compiling TypeScript, Visual Studio gives you the flexibility to choose which version of TypeScript to use on a per-project basis.
In MSBuild compilation scenarios, the TypeScript NuGet package is the recommended method of adding TypeScript compilation support to your project. Visual Studio will give you the option to add this package the first time you add a TypeScript file to your project. This package is also available at any time through the NuGet package manager. When the NuGet package is used, the corresponding language service version will be used for language support in your project. Note: The minimum supported version of this package is 3.6.
Projects configured for npm can specify their own version of the TypeScript language service by adding the TypeScript npm package. You can specify the version using the npm manager in supported projects. Note: The minimum supported version of this package is 2.1.
The TypeScript SDK has been deprecated in Visual Studio 2022. Existing projects that rely on the SDK should be upgraded to using the NuGet package. For projects that cannot be upgraded immediately, the SDK is still available on the Visual Studio Marketplace and as an optional component in the Visual Studio installer.
My understanding of this is that Visual Studio should respect the TypeScript version specified for the npm package. Yet, for some reason, the editor does not recognize a syntax that should be available in 3.8.
Is my understanding wrong? What should be done so that Visual Studio 2022 recognizes the optional chaining syntax in a .ts file?
Update: Since apparently the issue isn't clear enough.
Visual Studio CODE by default uses the Typescript version that it was shipped with to provide language support (note: you still need a tsc compiler to actually compile the code). The editor can automatically detect a Typescript version installed in the root folder of the project or in a different path if the typescript.tsdk
setting is used.
The question is how to get a similar behavior when using VS2022.
For testing purposes, I have created a new empty Angular Project. Out of the box the project was configured to use Typescript version 4+. I have edited the package.json
file to downgrade to 3.5.1 and run npm install to be sure that the project node folder is updated. In this case the intellisense still recognizes the optional chaining syntax even if the project now uses TS 3.5.1 (support was added only in 3.7).
Comparing the two project files I can see the other one includes a "Last" last, that I assume is a reference to the old sdk support. From what I see:
- having Last seems to make Visual Studio never recognize the optional chaining syntax even when using newer Typescript versions
- removing the line seems to have Visual Studio always recognize the optional chaining syntax even when using older Typescript versions
BTW, neither project displays any "Typescript Build" setting in the Properties window.
Again, the question is simple: How can I instruct Visual Studio 2022 to use the Typescript version that is installed locally in the project WITHOUT using the obsolete esternal sdk or having to pollute the project with nuget packages that try to override VS default behavious?