typescript - 如何让 Yarn 扁平化我的 TypeScript 类型?

标签 typescript yarnpkg

我已经安装了 @types/react@types/react-dom。假设它们之前是版本 15,然后我使用 yarn upgrade @types/react@16 @types/react-dom@16 升级了它们。

@types/react-dom 使用 "@types/react": "*" 声明对 @types/react 的依赖,即它应该能够与新安装的版本一起使用。但是,显然 Yarn 已将 @types/react@* 的依赖项锁定为 @types/react@^15.0.22

这样做的结果是 @types/react-dom 有自己的 React 类型副本,仍然是 v15 - 由于 TypeScript 开始提示我有重复的类型定义。

传递升级到 v16 的合适方法是什么?我可以避免手动编辑我的 yarn.lock 吗?

最佳答案

请注意,如果将来有人遇到此问题:我现在使用的解决方法是手动编辑我的 yarn.lock:

-"@types/react@*", "@types/react@^15.0.22":
+"@types/react@^15.0.22":
  version "15.0.24"
  resolved "https://registry.yarnpkg.com/@types/react/-/react-15.0.24.tgz#8a75299dc37906df327c18ca918bf97a55e7123b"

-"@types/react@^16":
+"@types/react@*", "@types/react@^16":
  version "16.0.9"
  resolved "https://registry.yarnpkg.com/@types/react/-/react-16.0.9.tgz#2ad952abbb22617620927694f9a4bce292d7fb2b"

换句话说,我指出指向 @types/react@* 的依赖项应该解析为与指向 @types/react@^16 的依赖项相同的结果>.

关于typescript - 如何让 Yarn 扁平化我的 TypeScript 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46583226/

相关文章:

typescript - SonarQube 未检测到 Angular-TypeScript 规则违规

javascript - Apple M1 芯片上的随机 "Assertion failed"错误

vue.js - 如何在没有 monorepo 的情况下在多个 vue 应用程序中组织代码(组件)共享

yarnpkg - 在同一个项目中使用NPM和Yarn有什么坏处吗?

typescript - 如何禁用 eslint no-promise-executor-return?

typescript - 为对象的键添加前缀仅考虑重叠

javascript - 在 Typescript 中填充一个空的、类型化的对象

javascript - 局部变量的可能性

javascript - 提交用户选择单选按钮值,其中值是从 json 定义的

node.js - 如何将 webpack 与 monorepo 一起使用(yarnpkg 工作区)