【问题标题】:TypeScript is using different versions of @types for reactTypeScript 使用不同版本的 @types 进行反应
【发布时间】:2019-04-07 03:06:00
【问题描述】:

我在tsconfig.json 中设置了我的compilerOptions,并使用了以下paths

"paths": {
  "react": ["node_modules/@types/react"],
  "@types/react":  ["node_modules/@types/react"]
}

然而,我可以看到 @types/react-router 正在使用它自己的 @types/react 版本,这会导致编译错误,例如:

ERROR in /path/to/node_modules/@types/react-router/node_modules/@types/react/index.d.ts
    ERROR in /path/to/node_modules/@types/react-router/node_modules/@types/react/index.d.ts(2297,27)
       TS1005: ';' expected.

如何强制所有模块使用我想要包含的 @types 版本?

【问题讨论】:

  • 您不应该像这样安装额外的@types/react 副本,因为最新版本的@types/react-router 依赖于允许任何版本的@types/react。你用什么工具来安装包? (npm、yarn 还是其他?)请将您的 package.json 文件添加到问题中,以便我可以尝试重现问题。

标签: javascript reactjs typescript types


【解决方案1】:
npm install @types/yourModule --save-dev

你可以试试吗

不要碰 tsconfig.json 文件

【讨论】:

    猜你喜欢
    • 2019-02-22
    • 2017-12-04
    • 2017-04-07
    • 1970-01-01
    • 2017-05-19
    • 2021-06-20
    • 2017-08-03
    • 2016-10-25
    • 2018-08-05
    相关资源
    最近更新 更多