react-native-community / react-native-template-typescript

👾 Clean and minimalist React Native template for a quick start with TypeScript.
https://www.npmjs.com/package/react-native-template-typescript
MIT License
1.86k stars 398 forks source link

Prevent installing multiple versions of `@types/react` #182

Closed newyankeecodeshop closed 3 years ago

newyankeecodeshop commented 3 years ago

This is an alternative to #181 to fix the compile errors from type checking dependencies. The compiler errors are caused by multiple copies of @types/react being brought in by yarn. This happens because both @types/react-native and @types/react-test-renderer declare a dependency on @types/react, but they have different version dependencies, which causes duplication:

"@types/react-native@^0.63.2":
  version "0.63.49"
  resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.63.49.tgz#b9a4781a0543763f0079c3ef2ba2148a4509b32e"
  dependencies:
    "@types/react" "*"

"@types/react-test-renderer@^16.9.2":
  version "16.9.5"
  resolved "https://registry.yarnpkg.com/@types/react-test-renderer/-/react-test-renderer-16.9.5.tgz#edab67da470f7c3e997f58d55dcfe2643cc30a68"
  dependencies:
    "@types/react" "^16"

"@types/react@*":
  version "17.0.2"
  resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.2.tgz#3de24c4efef902dd9795a49c75f760cbe4f7a5a8"
  dependencies:
    "@types/prop-types" "*"
    csstype "^3.0.2"

"@types/react@^16":
  version "16.14.4"
  resolved "https://registry.yarnpkg.com/@types/react/-/react-16.14.4.tgz#365f6a1e117d1eec960ba792c7e1e91ecad38e6f"
  dependencies:
    "@types/prop-types" "*"
    csstype "^3.0.2"

This PR resolves this by forcing the resolution of @types/react@* to match @types/react@^16. Then type-checking can be re-enabled for 3rd party libraries.

When we upgrade to React Native 0.64, which includes React 17.0.1, this resolution will have to be updated as well.