Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Duplicate identifier' error when compiling typescript definition files to wwwroot folder

I have created a ASP.NET 5 project which I use mainly for a front-end typescript application.

I'm using grunt and grunt-ts to do the compilation.

I have a 'src' folder where all my typescript files are contained

grunt-ts compiles everything in the 'src' folder and combines this to a single js file which is then put in the wwwroot folder. A typescript definition file is also generated and put in the wwwroot folder.

compiling with grunt/grunt-ts works flawlessly.

The problem: When the definition file exist in the wwwroot folder, the visual studio IDE starts giving me lots of 'Duplicate identifier' errors. This is of course because of the definition file.

Is there a way to make visual studio ignore the wwwroot folder (or any folder) for it's IDE/internal typescript compilation?

like image 504
Ivan L Avatar asked Oct 31 '22 04:10

Ivan L


1 Answers

You want to add a tsconfig.json file to the root of your project which contains the following:

{
  "compilerOptions": {
    "noImplicitAny": true,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": false,
    "module": "commonjs",
    "target": "es5"
  },
  "exclude": [
    "bower_components",
    "node_modules",
    "wwwroot"
  ]
}

The tsconfig.json file is responsible for configuring TypeScript compilation.

  • compilerOptions - TypeScript to JavaScript compilation options.
    • "noImplicitAny": true - Do not allow implicit any variables. Force them to be explicitly declared.
    • "noEmitOnError": true - Stop processing on error.
    • "removeComments": false - Do not remove comments.
    • "sourceMap": false - Do not create source map files (Leave this to the gulp plugin).
    • "module": "commonjs" - Use the Common JS modules.
    • "target": "es5" - Compile to ECMAScript 5.
  • exclude - Exclude the bower_components, node_modules and wwwroot folders from being scanned for TypeScript (.ts) or TypeScript definition (.d.ts) files.
like image 62
Muhammad Rehan Saeed Avatar answered Nov 09 '22 08:11

Muhammad Rehan Saeed