【发布时间】:2016-05-13 12:36:45
【问题描述】:
我正在努力让 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 中的其他定义...避免类型定义冲突的解释更多here
所以,当我运行 npm run tsc 时,我希望 tsc 忽略 main.d.ts 和 main 中的所有内容,但事实并非如此。
我在tsc ignores tsconfig.json when specific files are defined 看到过其他问题,但我这里没有这种情况。
为什么我的 tsconfig.json 被忽略了?为什么 tsc 对它这么刻薄?!
任何想法都将不胜感激!
哦,顺便说一句,错误只是像这样的几行错误 - 主文件夹和浏览器文件夹都会发生错误:
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 中切换到 exlcude browser 和 browser.d.ts 并在 src/typings.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.
【问题讨论】:
-
复制了哪些文件?你有哪个版本的 tsc (
tsc -v)?exclude语法在 1.6 和 1.8 之间有一些变化 -
也许这会对你有所帮助:stackoverflow.com/questions/36671555/…
-
我似乎在 1.8.10 上运行。我已经阅读了关于 >= 1.8 的更改 - 我不认为我所拥有的会受到影响....我显然是错的!就那个答案而言 - 我没有在我的排除数组中使用任何 **s。此外,我没有收到关于我的源代码的任何错误,只是关于我的类型定义文件:(.. 我没有看到这个问题,所以谢谢。
-
你能添加至少一条错误信息吗,这可能对我有帮助。
-
我添加了一个示例 :)
标签: typescript angular tsc