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