TS2300: Duplicate identifier问题的解

2019-11-01  本文已影响0人  Jtag特工

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"],
}
上一篇 下一篇

猜你喜欢

热点阅读