typescript - TypeScript:重复标识符“IteratorResult”
问题描述
我正在尝试通过tsc
- 我已在全球范围内安装 - 进行编译,但出现错误:
~/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
有自己的问题...)
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
。毕竟,这就是在全球范围内安装东西的全部意义所在。
与此同时,我有一个解决方法,就是别名 tsc (我在 Windows 中使用 git bash )。
alias tsc="path/to/project/node_modules/.bin/tsc.cmd"
解决方案
在 GitHub 上发现了一个相关的问题 - https://github.com/microsoft/TypeScript/issues/32333。@rbuckton 建议升级@types/node
。它对我有用。
推荐阅读
- biztalk - 计算 BizTalk 业务流程中文件夹中的文件数
- c# - 将图像从 GIF 转换为 JPEG
- javascript - Dropzone.js - 即使选择了选项,也删除不显示的链接
- servlets - 在 Servlet 中,“request.getParts().stream()...”添加了一个“空”Part 对象
- swift - 无法链接用户 id 以使用 firebase 写入数据库
- windows - AWS EC2 实例 -> Microsoft Windows Server -> 平稳运行 Power BI + 经济高效
- python - 没有名为“flask_security”的模块
- python - 解决 ValueError:无法将浮点 NaN 转换为整数
- jsonschema - OpenAPI oneOf 显示项目两次(问题)?
- excel - 循环粘贴工作表类的方法