我试图通过 我安装了 tsconfig.json 如果我全局卸载 同时,我有一个变通方法,那就是只使用tsc的别名(我在Windows中使用git bash)。~/AppData/Roaming/nvm/v11.15.0/node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6 - error TS2300: Duplicate identifier 'IteratorResult'.
41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
~~~~~~~~~~~~~~
node_modules/@types/node/index.d.ts:170:11
170 interface IteratorResult<T> { }
~~~~~~~~~~~~~~
'IteratorResult' was also declared here.
node_modules/@types/node/index.d.ts:170:11 - error TS2300: Duplicate identifier 'IteratorResult'.
170 interface IteratorResult<T> { }
~~~~~~~~~~~~~~
~/AppData/Roaming/nvm/v11.15.0/node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6
41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
~~~~~~~~~~~~~~
'IteratorResult' was also declared here.
Found 2 errors.
10.1.0版本。(code@last/code>有它自己的问题。。。)
{
"compilerOptions": {
"target": "es2018",
"moduleResolution": "node",
"module": "commonjs",
"jsx": "react",
"lib": [
"dom",
"es2018",
"dom.iterable",
"scripthost"
],
"typeRoots": [
"./node_modules/@types",
"./types"
],
"types": [],
"alwaysStrict": true,
"strictNullChecks": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"sourceMap": true,
"outDir": "dist"
},
"files": [
"app/index.tsx"
],
"include": [
"app/**/*.ts",
"app/**/*.tsx",
"test/**/*.ts",
"test/**/*.tsx",
"node_modules/@types/**/*.d.ts",
"./types/**/*.d.ts"
],
"exclude": [
"dist"
]
}
alias tsc="path/to/project/node_modules/.bin/tsc.cmd"
在github-https://GitHub.com/microsoft/typescript/issues/32333上发现相关问题。@rbuckton建议升级。对我有用。
我在我的angular 8应用程序中出现了错误,在尝试了所有的建议之后,包括已接受的答案,我还是无法解决这个问题。我不得不查看以前的一个angular 6应用程序,该应用程序编译时没有出错,我意识到我可以跳过库检查,包括
“SkipLibChecking”:true
到tsconfig.json文件。由于我的应用程序运行良好,没有问题,我决定采取这种方法。下面是tsconfig.json文件的完整配置
{ "compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"skipLibCheck": true
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
此配置后没有更多错误。注意:这并不意味着问题已经解决,但至少它允许我跳过导致错误的bug。由于我的应用程序正在按预期运行,我只是认为这个错误与此无关。
我怀疑是因为你的包含部分:
"include": [
"app/**/*.ts",
"app/**/*.tsx",
"test/**/*.ts",
"test/**/*.tsx",
"node_modules/@types/**/*.d.ts",
"./types/**/*.d.ts"
]
通常不需要显式地包含*.d.ts文件。而且可能从不声明来自其他库(或节点类型)的文件。
默认情况下,
检查tsconfig.json上的Typescript文档,它详细解释了“typeroots”,“files”和“include/exclude”配置选项。