7

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

7
  • 1
    .eslintignore will not help with ts compile errors. tsconfig.ignore should help. I had this working at one point, after encountering the same issue, but that was 2 years ago and I no longer have VS 2015 installed. Assuming that you are using the latest TypeScript (2.6.2), and that you have the latest installation of TS for VS 2015. Let me know if that is the case and I may be able to provide an answer. Commented Dec 23, 2017 at 17:23
  • 1
    You are likely missing "compilerOptions": {"types": []}} Please add an example of some of the specific errors to this question to help confirm. Commented Dec 23, 2017 at 17:25
  • Thanks Aluan. I tried your suggestion and it didn't work. I've added examples of some of the errors Commented Jan 2, 2018 at 21:41
  • does it work from the command line? Commented Jan 2, 2018 at 21:57
  • 1
    unfortunately ignore won't help you here. The reason is that it doesn't apply. When an import is traced to a module it's always included Commented Jan 3, 2018 at 9:47

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

legend been stuck on this for days
@JamesBlackburn BTW I found out that trying to upgrade from AngularJS to Angular creates a world of pain. On a different project we completely recreated the app in Angular from scratch, and it turns out to be much faster and easier that way. Maybe converting your main ts code is useful, but that's about all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.