美文网首页
TS2300: Duplicate identifier问题的解

TS2300: Duplicate identifier问题的解

作者: Jtag特工 | 来源:发表于2019-11-01 11:52 被阅读0次

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问题的解

      本文链接:https://www.haomeiwen.com/subject/nvsfbctx.html