From dbf8e3f5ba8636560898803f5c5973432bf61d1e Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Mon, 25 Mar 2024 12:23:16 -0700 Subject: [PATCH] Add @types/react as optional peerDependency on packages that use it (#43509) Summary: Now that RN is providing TS type information, many of those .d.ts files depend on types from react. In modern packagemanagers (Ex: pnpm) types/react will not be available to RN since it does not declare it as a dependency. I also noticed that the types for react-native-popup-menu-android appear to be pointing to the wrong location. Add types/react as a peerDependency on the packages that have .d.ts files that import from React. Add types/react to peerDependencyMeta with optional:true to prevent users not using TS from requiring types/react. ## Changelog: [GENERAL] [ADDED] Added types/react as an optional peerDependency Pull Request resolved: https://github.com/facebook/react-native/pull/43509 Reviewed By: cortinico Differential Revision: D55225940 Pulled By: NickGerleman fbshipit-source-id: 4cbab071928cb925baec45f55461559acc9a54e6 --- package.json | 2 +- packages/react-native-popup-menu-android/index.d.ts | 4 ++-- packages/react-native-popup-menu-android/package.json | 9 +++++++-- packages/react-native/package.json | 6 ++++++ packages/virtualized-lists/package.json | 6 ++++++ yarn.lock | 8 ++++---- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 9cd73bca5b65c2..7390be1214e2c7 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@react-native/metro-babel-transformer": "0.75.0-main", "@react-native/metro-config": "0.75.0-main", "@tsconfig/node18": "1.0.1", - "@types/react": "^18.0.18", + "@types/react": "^18.2.6", "@typescript-eslint/parser": "^7.1.1", "ansi-styles": "^4.2.1", "babel-plugin-minify-dead-code-elimination": "^0.5.2", diff --git a/packages/react-native-popup-menu-android/index.d.ts b/packages/react-native-popup-menu-android/index.d.ts index 9caa4c385a77e4..9539572f172798 100644 --- a/packages/react-native-popup-menu-android/index.d.ts +++ b/packages/react-native-popup-menu-android/index.d.ts @@ -7,5 +7,5 @@ * @format */ -export type {default} from './PopupMenuAndroid'; -export type {PopupMenuAndroidInstance} from './PopupMenuAndroid'; +export type {default} from './js/PopupMenuAndroid'; +export type {PopupMenuAndroidInstance} from './js/PopupMenuAndroid'; diff --git a/packages/react-native-popup-menu-android/package.json b/packages/react-native-popup-menu-android/package.json index 99f52be3071303..1723b8836b76c6 100644 --- a/packages/react-native-popup-menu-android/package.json +++ b/packages/react-native-popup-menu-android/package.json @@ -2,8 +2,7 @@ "name": "@react-native/popup-menu-android", "version": "0.75.0-main", "description": "PopupMenu for the Android platform", - "react-native": "js/PopupMenuAndroid", - "source": "js/PopupMenuAndroid", + "main": "index.js", "files": [ "js", "android", @@ -21,9 +20,15 @@ "@react-native/codegen": "0.75.0-main" }, "peerDependencies": { + "@types/react": "^18.2.6", "react": "*", "react-native": "*" }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + }, "dependencies": { "nullthrows": "^1.1.1" }, diff --git a/packages/react-native/package.json b/packages/react-native/package.json index 704d7970419039..3edf3fc0e40823 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -98,8 +98,14 @@ "featureflags-update": "node ./scripts/featureflags/index.js" }, "peerDependencies": { + "@types/react": "^18.2.6", "react": "18.2.0" }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + }, "dependencies": { "@jest/create-cache-key-function": "^29.6.3", "@react-native-community/cli": "14.0.0-alpha.0", diff --git a/packages/virtualized-lists/package.json b/packages/virtualized-lists/package.json index b2c745ef3c2e10..fe1488f4aa5e66 100644 --- a/packages/virtualized-lists/package.json +++ b/packages/virtualized-lists/package.json @@ -27,7 +27,13 @@ "react-test-renderer": "18.2.0" }, "peerDependencies": { + "@types/react": "^18.2.6", "react": "*", "react-native": "*" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } } } diff --git a/yarn.lock b/yarn.lock index b4424daf83333a..49ef43b0a66d11 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2767,10 +2767,10 @@ resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf" integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w== -"@types/react@^18.0.18": - version "18.0.20" - resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.20.tgz#e4c36be3a55eb5b456ecf501bd4a00fd4fd0c9ab" - integrity sha512-MWul1teSPxujEHVwZl4a5HxQ9vVNsjTchVA+xRqv/VYGCuKGAU6UhfrTdF5aBefwD1BHUD8i/zq+O/vyCm/FrA== +"@types/react@^18.2.6": + version "18.2.67" + resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.67.tgz#96b7af0b5e79c756f4bdd981de2ca28472c858e5" + integrity sha512-vkIE2vTIMHQ/xL0rgmuoECBCkZFZeHr49HeWSc24AptMbNRo7pwSBvj73rlJJs9fGKj0koS+V7kQB1jHS0uCgw== dependencies: "@types/prop-types" "*" "@types/scheduler" "*"