title: How does Visual Studio 2022 determine which TypeScript version to target for Intellisense purposes
body: <p>I am using Visual Studio 2022 to work on an existing solution that contains a web project with a node app.</p>
  <p>The app is configured in the <code>package.json</code> 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 &quot;TS1109:Expression expected&quot;. Node version if that matters is 14.17.0. <strong>No Typescript version is installed globally.</strong></p>
  <p><a href="https://docs.microsoft.com/en-us/visualstudio/javascript/javascript-in-visual-studio?view=vs-2022" rel="nofollow noreferrer">This page</a> states that</p>
  <blockquote>
  <p>By default, <strong>Visual Studio 2022 provides language support for JavaScript and TypeScript files to power IntelliSense without any specific project configuration</strong>.</p>
  <p>For compiling TypeScript, Visual Studio gives you the flexibility to choose which version of TypeScript to use on a per-project basis.</p>
  <p>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.</p>
  <p><strong>Projects configured for npm can specify their own version of the TypeScript language service by adding the TypeScript npm package</strong>. You can specify the version using the npm manager in supported projects. Note: The minimum supported version of this package is 2.1.</p>
  <p>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.</p>
  </blockquote>
  <p>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.</p>
  <p>Is my understanding wrong? What should be done so that Visual Studio 2022 recognizes the optional chaining syntax in a .ts file?</p>
  <hr />
  <p>Update: Since apparently the issue isn't clear enough.</p>
  <p>Visual Studio <strong>CODE</strong> by default uses the Typescript version that it was shipped with to provide <em><strong>language support</strong></em> (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 <code>typescript.tsdk</code> setting is used.</p>
  <p>The question is <strong>how to get a similar behavior when using VS2022</strong>.
  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 <code>package.json</code> 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).</p>
  <p>Comparing the two project files I can see the other one includes a &quot;Last&quot; last, that I assume is a reference to the old sdk support.
  From what I see:</p>
  <ul>
  <li>having Last seems to make Visual Studio <strong>never</strong> recognize the optional chaining syntax even when using <strong>newer</strong> Typescript versions</li>
  <li>removing the line seems to have Visual Studio <strong>always</strong> recognize the optional chaining syntax even when using <strong>older</strong> Typescript versions</li>
  </ul>
  <p>BTW, neither project displays any &quot;Typescript Build&quot; setting in the Properties window.</p>
  <p><a href="https://i.stack.imgur.com/ufahI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ufahI.png" alt="enter image description here" /></a></p>
  <p>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?</p>