Friday, February 24, 2017

TypeScript Errors TS2300 and TS2374 in VS2017 RC

We recently updated to Visual Studio 2017 RC from Visual Studio 2013. I won't go into the details why we skipped Visual Studio 2015.

The upgrade at some point then trigger to update to the latest TypeScript toolset version (2.1 at the time of writing).

We then notice a series of TypeScript compiler errors with codes TS2300 and TS2374. It turns out that the compiler was actually happy. The error list is created by IntelliSense. To identify them as generated by IntelliSense you need to ensure that you select "IntelliSense Only" from the drop-down list in the "Error List" view of Visual Studio (VS) (click image to enlarge it):


In our case we observed the following errors:
  • TS2300 Duplicate identifier 'export='
  • TS2374 Duplicate string index signature
  • TS2375 Duplicate number index signature
When we check for the files for which these were recorded, we discovered that these were related to jQuery.d.ts, knockout.d.ts and index.d.ts. All of these files were part of the latest NuGet package for either jQuery or Knockout, so outside of our control.

After some experimentation we identified adding a tsconfig.json file to the project solved the problem.

Here is the complete content of the tsconfig.json file:

{
}

In other words: apart from the curly braces it is empty. We placed this file in the same directory as the project file (Web.csproj in our case) and included it in the project.

The file tsconfig.json does not have to be empty. You are free to add settings as needed. The key point for us was to avoid the false positive by IntelliSense.

With VS 2013 it worked without tsconfig.json. However, it looks as if the tooling has changed and that for IntelliSense to work correctly the file has to be present.

In closing, a gentle reminder to select "Build + IntelliSense" from the drop-down list in the "Error List" to see all errors again (if any). Here is an image that shows this as well as the location for the tsconfig.json file (click image to enlarge it):


Happy coding!

0 comments:

Post a Comment

All comments, questions and other feedback is much appreciated. Thank you!