TS2300: Duplicate identifier问题的解决

Posted Jtag特工

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TS2300: Duplicate identifier问题的解决相关的知识,希望对你有一定的参考价值。

TS2300: Duplicate identifier问题的解决

Typescript编译时遇到d.ts中的定义冲突:

tsc -p ./
../../../../../Users/lusin/AppData/Roaming/npm/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:77:11
    77 interface IteratorResult<T>  
                 ~~~~~~~~~~~~~~
    'IteratorResult' was also declared here.

../node_modules/@types/node/index.d.ts:77:11 - error TS2300: Duplicate identifier 'IteratorResult'.

77 interface IteratorResult<T>  
             ~~~~~~~~~~~~~~

  ../../../../../Users/lusin/AppData/Roaming/npm/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.

解决方案是在tsconfig.json的compilerOption中加入下面两项:

		"skipLibCheck": true,
		"allowSyntheticDefaultImports": true

完整例子:


	"compilerOptions": 
		"module": "commonjs",
		"target": "es6",
		"outDir": "out",
		"rootDir": "src",
		"sourceMap": true,
		"skipLibCheck": true,
		"allowSyntheticDefaultImports": true
	,
	"include": ["src"],
	"exclude": ["node_modules", ".vscode-test"],

以上是关于TS2300: Duplicate identifier问题的解决的主要内容,如果未能解决你的问题,请参考以下文章

3GPP TS 23501-g51 中英文对照 | 5.2.3 Identification and authentication

TS2300:重复标识符“路由器”

错误 TS2300:重复标识符“导出 =”

错误 TS2300:重复标识符“RequestInfo”

错误 TS2300:node_modules/@types/core-js/index.d.ts 中的标识符“PropertyKey”重复

错误 TS2339:“主页”类型上不存在属性“路由器”