fix: make codegenNativeComponent's return type nameable by consumers - #58102
Open
artus9033 wants to merge 1 commit into
Open
fix: make codegenNativeComponent's return type nameable by consumers#58102artus9033 wants to merge 1 commit into
codegenNativeComponent's return type nameable by consumers#58102artus9033 wants to merge 1 commit into
Conversation
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
Contributor
Author
|
CC @huntie |
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.