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

只愿长相守 提交于 2020-01-14 09:52:27

问题


I have created a ASP.NET 5 project wich 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 wich 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 ?


回答1:


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.



回答2:


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

Exclude it from your project.



来源:https://stackoverflow.com/questions/30211885/duplicate-identifier-error-when-compiling-typescript-definition-files-to-wwwro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!