Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 639
Erwan Joly Avatar asked Dec 15 '21 09:12

Erwan Joly


1 Answers

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

like image 179
Erwan Joly Avatar answered Oct 06 '22 20:10

Erwan Joly