Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2015 - errors on *.d.ts files in node_modules folder

I'm upgrading a project from Angular JS to Angular 4. TypeScript is already used in the Angular JS project, and after converting it I'm getting thousands of errors in Visual Studio for 3rd party typescript typing files (*.d.ts). I'm also getting a few errors in Visual Studio on the actual TypeScript files.

The TypeScript code compiles successfully when I use the command line TypeScript compiler (tsc), so I want to prevent compile checking of all *.d.ts files.

I've reviewed answers for very similar problems that suggest how to ignore these errors however none on them work for me, and most of them relate to VS 2017.

Here's what I've tried, to disable compile checking:

Added 'TypeScriptCompileBlocked' to .csproj file:

   <PropertyGroup>
      <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
      ....
   </PropertyGroup>
  • then close and re-open VS

Added .eslintignore file

I've added an .eslintignore file to the project root, with a setting to ignore all *.d.ts files:

**/*.d.ts
**/node_modules/*

Disable ESLint

Under VS Tools > Options, I've looked for an option, but there is no option to do this in VS2015

tsconfig.json - exclude node_modules folder

"exclude": [
  "./node_modules/*"
]

-- I've also tried --   

   "node_modules"
   ... and
   "**/*.d.ts"

tsconfig.json - set "compileOnSave": false

{
  "compilerOptions": {
    "compileOnSave": false
  }
}

also I've added the following to "compilerOptions":

"types": []

I've also set various other compilerOptions to ignore errors, although the errors I'm seeing aren't related to these:

"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"noStrictGenericChecks": true

What do I have to do to ignore the *.d.ts files? Here's a sample of some of the errors I'm seeing in the file node_modules\@angular\common\src\directives\ng_class.d.ts:

enter image description here

The current project configuration is:

  • compiler (tsc) version = 1.8
  • TypeScript version = 2.6.2 (installed via npm)
  • There are no TypeScript configuration options set directly through the Visual Studio project (i.e. in the .csproj file)

My full tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "ES2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
    "noStrictGenericChecks": true
  },
  "include": [ "**/*.ts" ],
  "exclude": [
    "node_modules"
  ]
}

(in regard to the value I'm using for module, here's what the MicroSoft documentation says):

"ES6" and "ES2015" values may be used when targeting "ES5" or lower.

https://www.typescriptlang.org/docs/handbook/compiler-options.html

I've also tried using "commonjs" as the value

like image 429
Chris Halcrow Avatar asked Nov 08 '22 12:11

Chris Halcrow


1 Answers

I found out that the npm installed TypeScript I have is a completely independent installation of TypeScript (I 'node installed' grunt-ts for build-automated typescript compilation, and for some reason grunt-ts needs this 'node installed' TypeScript). Visual Studio wasn't using the node-installed TypeScript when it was trying to compile, it was using a TypeScript 1.8 compiler that's installed specifically for Visual Studio.

To install TypeScript 2.6.2 for use by VS2015, I installed it from here:

https://www.microsoft.com/en-us/download/details.aspx?id=48593

This created a folder C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.6, that contains a tsc.exe. I then set this in my .csproj file

<TypeScriptToolsVersion>2.6</TypeScriptToolsVersion>

and that fixed all of the errors.

To get the project building I also needed to include my tsconfig.json file in the project (right click > include in project). That causes Visual Studio to ignore the TypeScript configuration in the .csproj file and use tsconfig.json instead

I had to unload and re-load the project a few times, saving in between, until the VS2015 project properties were recognised by Visual Studio as being disabled. Closing and re-opening Visual Studio, saving any changes to the project if prompted, would probably achieve the same thing:

enter image description here

So it looks like the reason nothing was working to ignore the d.ts files is because Visual Studio wasn't able to correctly interpret the solution and produce the expected output.

like image 147
Chris Halcrow Avatar answered Nov 15 '22 06:11

Chris Halcrow