TypeScript:重复的标识符"IteratorResult" [英] TypeScript: Duplicate identifier 'IteratorResult'

查看:687
本文介绍了TypeScript:重复的标识符"IteratorResult"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过tsc进行编译-我已在全球范围内进行了安装-并出现错误:

I'm trying to compile via tsc--which I've installed globally--and I'm getting an error:

~/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.

我安装了@types/node版本10.1.0. (@latest有其自身的问题...)

I have @types/node version 10.1.0 installed. (@latest has its own issues...)

tsconfig.json

{
  "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"
  ]
}

如果我全局卸载typescript并运行npx tsc,它可以工作,但是全局安装和运行typescript应该没有任何问题.毕竟,这就是在全局范围内进行安装的全部要点.

If I uninstall typescript globally and run npx tsc it works, but there should be nothing wrong with installing and running typescript globally. After all, that's the whole point of installing things globally.

同时,我有一种解决方法,就是仅对tsc进行别名(我在Windows中使用git bash).

In the meantime I have a workaround which is to just alias tsc (I'm using git bash in Windows).

alias tsc="path/to/project/node_modules/.bin/tsc.cmd"

推荐答案

在GitHub上发现了一个问题-相关的https://github.com/microsoft/TypeScript/issues/32333 . @rbuckton建议升级@types/node.它为我工作.

Found an issue on GitHub - https://github.com/microsoft/TypeScript/issues/32333 which was related. @rbuckton suggested upgrading @types/node. It worked for me.

这篇关于TypeScript:重复的标识符"IteratorResult"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆