TSC似乎无法从tsconfig.json中获取“exclude”选项

4

我正在努力让tsc识别我的tsconfig.json文件并编译我的.ts文件。它遇到了重复错误,我正在尝试通过我的tsconfig.json来避免这些错误。

我已经做了以下几点:

package.json
tsconfig.json
typings.json
typings /
    main/ ...etc
    browser/ ...etc
    main.d.ts
    browser.d.ts
src / ...   <source files in here.>

我的typings.json文件如下:

{
  "ambientDependencies": {
    "es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654",
    "jasmine": "registry:dt/jasmine#2.2.0+20160412134438",
    "node": "registry:dt/node#4.0.0+20160509154515"
  }
}

我的tsconfig.json文件如下所示:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "bower_components",
    "typings/main",
    "typings/main.d.ts"
  ]
}

在我的“package.json / tests”对象中,我有以下内容:

 "tsc": "tsc",

因此,我期望我的tsconfig.json告诉tsc忽略main.d.ts和main中的其他定义...更多关于避免类型定义冲突的解释可以在这里找到。
所以,当我运行npm run tsc时,我期望tsc忽略main.d.ts和main中的所有内容,但它没有。
我看到其他问题,在那些问题中,当定义了特定文件时,tsc会忽略tsconfig.json,但在这里我没有这种情况。
为什么我的tsconfig.json被忽略了?为什么tsc对它如此不友好?
如果有任何想法,将不胜感激!
哦,顺便说一下,错误只是几行像这样的错误 - 错误发生在main和browser文件夹中:
typings/main/ambient/node/index.d.ts(2067,18): error TS2300: Duplicate identifier 'PassThrough'.
typings/main/ambient/node/index.d.ts(2072,9): error TS2300: Duplicate identifier 'showHidden'.
typings/main/ambient/node/index.d.ts(2073,9): error TS2300: Duplicate identifier 'depth'.
typings/main/ambient/node/index.d.ts(2074,9): error TS2300: Duplicate identifier 'colors'.
typings/main/ambient/node/index.d.ts(2075,9): error TS2300: Duplicate identifier 'customInspect'.
typings/main/ambient/node/index.d.ts(2136,5): error TS2300: Duplicate identifier 'export='.
typings/main/ambient/node/index.d.ts(2144,9): error TS2300: Duplicate identifier 'isRaw'.
typings/main/ambient/node/index.d.ts(2146,9): error TS2300: Duplicate identifier 'isTTY'.
typings/main/ambient/node/index.d.ts(2149,9): error TS2300: Duplicate identifier 'columns'.
typings/main/ambient/node/index.d.ts(2150,9): error TS2300: Duplicate identifier 'rows'.
typings/main/ambient/node/index.d.ts(2151,9): error TS2300: Duplicate identifier 'isTTY'.
typings/main/ambient/node/index.d.ts(2158,18): error TS2300: Duplicate identifier 'Domain'.

编辑:

在我的tsconfig.json中交换,将浏览器和browser.d.ts排除在外,并在我的参考路径中引用typings/main.d.ts在中,我只会得到以下这些错误:

src/typings.d.ts(3,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'module' must be of type 'NodeModule', but here has type '{ id: string; }'.
typings/main.d.ts(1,1): error TS6053: File 'typings/main/ambient/angular-protractor/index.d.ts' not found.
typings/main.d.ts(5,1): error TS6053: File 'typings/main/ambient/selenium-webdriver/index.d.ts' not found.

也许这个链接可以帮到你:https://dev59.com/3FoV5IYBdhLWcg3wIbtT#36716815 - Dinistro
1
我已经添加了一个示例 :) - dafyddPrys
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Dinistro
针对 Node.js 的错误,您可以在 d.ts 文件中添加以下内容,或者包含 node 的 typings:interface NodeModule { id: string; } declare var module: NodeModule;对于其他错误,请检查文件是否存在。 - Madhu Ranjan
这是个奇怪的事情,为什么它会查找 angular-potractor 和 selenium-webdriver,而它们并不在我的 typings.json 中呢? - dafyddPrys
显示剩余5条评论
1个回答

4
问题在于您在某个地方引用了被排除的 main.d.ts。这将从 tsc 加载并导致重复。

1
是的,你说得基本上是对的。在我的src/typings.d.ts文件中,我仍然保留了指向(我认为已经被排除了)main.d.ts文件的引用路径。删除这个引用后,我就可以将其重新排除主要的main和main.d.ts文件了。 - dafyddPrys

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接