From fd5eb68251c1664355421130e8d57e3e04b924d4 Mon Sep 17 00:00:00 2001 From: artus9033 Date: Mon, 24 Aug 2026 18:10:48 +0200 Subject: [PATCH] Make codegenNativeComponent's return type nameable by consumers --- .../Libraries/Utilities/codegenNativeComponent.js | 6 +++++- packages/react-native/ReactNativeApi.d.ts | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/react-native/Libraries/Utilities/codegenNativeComponent.js b/packages/react-native/Libraries/Utilities/codegenNativeComponent.js index cb5ece90df68..38a664f90c9e 100644 --- a/packages/react-native/Libraries/Utilities/codegenNativeComponent.js +++ b/packages/react-native/Libraries/Utilities/codegenNativeComponent.js @@ -23,6 +23,10 @@ type NativeComponentOptions = Readonly<{ excludedPlatforms?: ReadonlyArray<'iOS' | 'android'>, }>; +// Note that this alias is not re-exported from the `react-native` root, +// so it must not be used in public interfaces, such as the declared return type of +// `codegenNativeComponent` below: consumers that emit declaration files would be +// unable to name it portably (TS2883). export type NativeComponentType = HostComponent; // If this function runs then that means the view configs were not @@ -34,7 +38,7 @@ export type NativeComponentType = HostComponent; function codegenNativeComponent( componentName: string, options?: NativeComponentOptions, -): NativeComponentType { +): HostComponent { if (global.RN$Bridgeless === true && __DEV__) { console.warn( `Codegen didn't run for ${componentName}. This will be an error in the future. Make sure you are using @react-native/babel-preset when building your JavaScript code.`, diff --git a/packages/react-native/ReactNativeApi.d.ts b/packages/react-native/ReactNativeApi.d.ts index c1ac9628efe7..0d0b41ee5a57 100644 --- a/packages/react-native/ReactNativeApi.d.ts +++ b/packages/react-native/ReactNativeApi.d.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<2199d280ef42e2a63ec4d6c405af893a>> + * @generated SignedSource<<8ef03fa7fcadd865b637e8483e04005b>> * * This file was generated by scripts/js-api/build-types/index.js. */ @@ -1739,7 +1739,7 @@ declare type codegenNativeComponent = typeof codegenNativeComponent declare function codegenNativeComponent_default( componentName: string, options?: NativeComponentOptions, -): NativeComponentType +): HostComponent declare namespace CodegenTypes { export { BubblingEventHandler, @@ -3087,7 +3087,6 @@ declare type NativeComponentOptions = { declare namespace NativeComponentRegistry { export { setRuntimeConfigProvider, get, getWithFallback_DEPRECATED } } -declare type NativeComponentType = HostComponent declare class NativeEventEmitter< TEventToArgsMap extends Readonly< Record> @@ -6046,7 +6045,7 @@ export { VirtualizedSectionListProps, // f42f54c4 WrapperComponentProvider, // 9ef54e61 codegenNativeCommands, // 628a7c0a - codegenNativeComponent, // 32a1bca6 + codegenNativeComponent, // 520daa94 findNodeHandle, // 93f80214 processColor, // 6e877698 registerCallableModule, // 839c8cfe