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 = IteratorYieldResult | IteratorReturnResult;
        ~~~~~~~~~~~~~~

  ../node_modules/@types/node/index.d.ts:77:11
    77 interface IteratorResult { }
                 ~~~~~~~~~~~~~~
    'IteratorResult' was also declared here.

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

77 interface IteratorResult { }
             ~~~~~~~~~~~~~~

  ../../../../../Users/lusin/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6
    41 type IteratorResult = IteratorYieldResult | IteratorReturnResult;
            ~~~~~~~~~~~~~~
    '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问题的解决)