Repository navigation
Conversation
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
Contributor
Author
|
CC @huntie |
|
@fabriziocucci has imported this pull request. If you are a Meta employee, you can view this in D117336232. |
|
@fabriziocucci merged this pull request in 391723e. |
tvinhas
pushed a commit
to tvinhas/react-native-macos
that referenced
this pull request
Oct 21, 2026
react#58102) Summary: `codegenNativeComponent()` declared its return type as `NativeComponentType<Props>`. That alias lives in `Libraries/Utilities/codegenNativeComponent.js` and is not re-exported from the `react-native` root, and the package's `exports` map has no `./types_generated/*` subpath, so the deep specifier is not resolvable either. As a result, any library that calls `codegenNativeComponent()` and emits declaration files fails to build under `moduleResolution: node16/nodenext/bundler` - TypeScript cannot name the inferred return type portably: ``` src/ReactNativeTestViewNativeComponent.ts:11:1 - error TS2883: The inferred type of 'default' cannot be named without a reference to 'NativeComponentType' from '../node_modules/react-native/types_generated/Libraries/Utilities/codegenNativeComponent'. This is likely not portable. A type annotation is necessary. 11 export default codegenNativeComponent<NativeProps>('ReactNativeTestView'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` This is the default `fabric-view` template from `create-react-native-library`, so every new Fabric view library hits it. It used to work before RN 0.87.0, until react#57490 has removed visibility of the internally exported types. Example of breakage - this test run in `react-native-builder-bob`: https://github.com/callstack/react-native-builder-bob/actions/runs/32675382955/job/97282442650#step:19:20 ### Fix The fix is to declare the return type as `HostComponent<Props>` instead. `NativeComponentType<T>` is defined as `HostComponent<T>`, but only `HostComponent` is exported from root. Consumers can reach it via `import('react-native').HostComponent<Props>`. ## Changelog: [GENERAL] [FIXED] - Fix TS2883 when building declaration files for libraries that use `codegenNativeComponent` due to unreachable `NativeComponentType<T>` Pull Request resolved: react#58102 Test Plan: Tested locally on a library generated with Bob. Reviewed By: cipolleschi Differential Revision: D117336232 Pulled By: fabriziocucci fbshipit-source-id: 173fcfbc568cc4a8e79c32d16fbcee988db9b104
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
codegenNativeComponent()declared its return type asNativeComponentType<Props>. That alias lives inLibraries/Utilities/codegenNativeComponent.jsand is not re-exported from thereact-nativeroot, and the package'sexportsmap has no./types_generated/*subpath, so the deep specifier is not resolvable either.As a result, any library that calls
codegenNativeComponent()and emits declaration files fails to build undermoduleResolution: node16/nodenext/bundler- TypeScript cannot name the inferred return type portably:This is the default
fabric-viewtemplate fromcreate-react-native-library, so every new Fabric view library hits it.It used to work before RN 0.87.0, until #57490 has removed visibility of the internally exported types.
Example of breakage - this test run in
react-native-builder-bob: https://github.com/callstack/react-native-builder-bob/actions/runs/32675382955/job/97282442650#step:19:20Fix
The fix is to declare the return type as
HostComponent<Props>instead.NativeComponentType<T>is defined asHostComponent<T>, but onlyHostComponentis exported from root. Consumers can reach it viaimport('react-native').HostComponent<Props>.Changelog:
[GENERAL] [FIXED] - Fix TS2883 when building declaration files for libraries that use
codegenNativeComponentdue to unreachableNativeComponentType<T>Test Plan:
Tested locally on a library generated with Bob.