如何让Yarn压平我的TypeScript打字?

时间:2017-10-05 10:17:43

标签: 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吗?

1 个答案:

答案 0 :(得分:0)

请注意以后是否有人遇到此问题:我现在使用的解决方法是手动编辑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的依赖关系解析为相同的结果。