将打字稿定义文件编译到wwwroot文件夹时出现“重复标识符"错误 [英] 'Duplicate identifier' error when compiling typescript definition files to wwwroot folder

查看:63
本文介绍了将打字稿定义文件编译到wwwroot文件夹时出现“重复标识符"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个ASP.NET 5项目,主要用于前端打字稿应用程序.

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

我正在使用grunt和grunt-ts进行编译.

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

我有一个'src'文件夹,其中包含我所有的打字稿文件

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

grunt-ts编译"src"文件夹中的所有内容,并将其组合为单个js文件,然后将其放入wwwroot文件夹中.还将生成一个打字稿定义文件,并将其放在wwwroot文件夹中.

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.

使用grunt/grunt-ts编译可以完美地工作.

compiling with grunt/grunt-ts works flawlessly.

问题:当wwwroot文件夹中存在定义文件时,Visual Studio IDE会给我很多重复标识符"错误.这当然是因为定义文件.

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.

是否有一种方法可以使Visual Studio的IDE/内部打字稿编译忽略wwwroot文件夹(或任何文件夹)?

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

推荐答案

您想将 tsconfig.json 文件添加到项目的根目录,该文件包含以下内容:

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"
  ]
}

tsconfig.json 文件负责配置TypeScript编译.

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

  • editorOptions-TypeScript到JavaScript的编译选项.
    • "noImplicitAny":true-不允许隐式包含任何变量.强制将它们明确声明.
    • "noEmitOnError":true-停止处理错误.
    • "removeComments":否-不删除评论.
    • "sourceMap":否-不创建源地图文件(将其保留到gulp插件中).
    • 模块":"commonjs"-使用通用JS模块.
    • 目标":"es5"-编译为ECMAScript 5.

    这篇关于将打字稿定义文件编译到wwwroot文件夹时出现“重复标识符"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆