【问题标题】:How do I get Yarn to flatten my TypeScript typings?如何让 Yarn 扁平化我的 TypeScript 类型?
【发布时间】:2017-10-05 10:17:42
【问题描述】:

我已经安装了@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吗?

【问题讨论】:

    标签: typescript yarnpkg


    【解决方案1】:

    如果将来有人遇到此问题,请注意:我现在使用的解决方法是手动编辑我的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 的依赖项相同的结果。

    【讨论】:

      猜你喜欢
      • 2016-04-05
      • 2020-06-04
      • 2021-02-20
      • 1970-01-01
      • 2018-05-24
      • 2011-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多