打字稿:重复标识符“IteratorResult" [英] TypeScript: Duplicate identifier 'IteratorResult'

查看:19
本文介绍了打字稿:重复标识符“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.

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

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