How do I get Yarn to flatten my TypeScript typings?

Viewed 261

I've installed both @types/react and @types/react-dom. Let's say they were at version 15 before, and that I then upgraded both using yarn upgrade @types/react@16 @types/react-dom@16.

@types/react-dom declares a dependency on @types/react using "@types/react": "*", i.e. it should be able to work with the newly installed version. However, apparently Yarn has locked dependencies on @types/react@* to @types/react@^15.0.22.

The result of this is that @types/react-dom has its own copy of the React typings, still at v15 - due to which TypeScript starts to complain that I have duplicate type definitions.

What is the appropriate way to upgrade to v16 transitively? Can I avoid manually editing my yarn.lock?

1 Answers

Note for if anyone comes across this in the future: the workaround I've used for now is to manually edit my 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"

In other words, I indicate that dependencies pointed at @types/react@* should resolve to the same result as those that point to @types/react@^16.

Related