'How do I prevent VS 2022 to display typescript errors with d.ts files in esproj

I created a project (.esproj) for my SPA under visual studio 2022. It build well but visual studio is showing a lot of errors (only on .dt.ts files from node_modules of the project and also from the one of Typescript locally installed in AppData).

The errors are not showing up on VS Code but ideally I would use visual studio 2022 for this.

Here my esproj

<Project Sdk="Microsoft.VisualStudio.JavaScript.Sdk/0.5.0-alpha">
    <PropertyGroup Label="Globals">
        <ProjectGuid>6b86a87b-eb34-43fe-9cbb-99a2e3db4e41</ProjectGuid>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <StartupCommand>set BROWSER=none&amp;&amp;npm start</StartupCommand>
        <JavaScriptTestRoot>src\</JavaScriptTestRoot>
        <JavaScriptTestFramework>Jest</JavaScriptTestFramework>
    </PropertyGroup>
    <ItemGroup>
        <Script Include="**" Exclude="*.esproj;**\node_modules\**" />
    </ItemGroup>

    <!-- This target is copied from the ASP.NET SPA template in order to ensure node_modules are in place. -->
    <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
        <!-- Ensure Node.js is installed -->
        <Exec Command="node --version" ContinueOnError="true">
            <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
        </Exec>
        <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
        <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
        <Exec WorkingDirectory="$(SpaRoot)" Command="npm install --legacy-peer-deps" />
    </Target>
</Project>

here my tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "ESNext",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ],
  "exclude": [
    "node_modules"
  ]
}

Any idea how I can configure visual studio 2022 to not run analyzer on .d.ts ?

Thanks in advance



Solution 1:[1]

Replacing the payload part

 <ItemGroup>
        <Script Include="**" Exclude="*.esproj;**\node_modules\**" />
    </ItemGroup>

by

  <ItemGroup>
    <Script Include="**"/>
    <Script Remove="**.d.ts"/>
  </ItemGroup>

seems to solve my issue

Solution 2:[2]

  1. In Visual Studio, Right click the node_modules folder and select 'Exclude From Project' if not already set.
  2. Close your solution in VS.
  3. Using File Explorer, set the properties of the node_modules folder to Hidden (do not apply to sub folders).
  4. Open your solution.

Faster solution load, no more intellisense errors, NPM still works even though the folder is hidden.

Solution 3:[3]

This worked for me change .csproj to include this setting inside PropertyGroup:

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 John Rah
Solution 3 user3670176