Make generated props and style types augmentable - #58168
Open
zoontek wants to merge 3 commits into
Open
Conversation
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
zoontek
force-pushed
the
augmentable-props-and-styles
branch
from
August 27, 2026 14:52
db50e6b to
39ab067
Compare
Revert convertTypeAliasesToInterfaces to its original form. Get the same emitted types from the Flow sources instead. Styles: rename ____ViewStyle_Internal, ____TextStyle_Internal and ____ImageStyle_Internal to ViewStyle, TextStyle and ImageStyle. StyleSheet now re-exports each name unchanged, with no alias. Props: 11 annotated types still emitted members in the interface body. Each one now moves its inline members into a private <Name>Core alias. All members are inherited through the extends clause, so a module augmentation can refine them. ImagePropsBase and ImageBackgroundProps declare members that shadow keys of the type they spread. An explicit Omit removes those keys, because a Flow spread of an optional property unions the two types instead of replacing the member. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
@christophpurrer has imported this pull request. If you are a Meta employee, you can view this in D117876097. |
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:
react-native-web and Nativewind extend React Native's types with module augmentation. #58062 made the props and style types interfaces, which cleared the duplicate identifier errors. Two things still can't be extended.
Styles:
ViewStyleis an interface derived from____ViewStyle_Internal, butViewProps['style']reads the base, so augmentingViewStyledoesn't reach it:____ViewStyle_Internalis now namedViewStyle, and the same for Text and Image.StyleSheetre-exports each name unchanged, so the interface and the base are one symbol.Props written as inline object literals: The transform copies them into the interface body, where a second declaration is a merge conflict rather than an override, so the augmentation is silently ignored. Eleven of the 24 annotated types are affected. Each now moves its inline members into a private
<Name>Corealias, so they reach the interface through the extends clause and are inherited, like everything fromViewPropsalready was:That costs 11 new names in the API snapshot, one per affected type.
PressablePropsset the precedent withPressableBaseProps.ImagePropsBaseandImageBackgroundPropsdeclare members that shadow keys of the type they spread, and a Flow spread of an optional property unions the two types instead of replacing the member, so those keys get an explicitOmit.Caveat: an augmented member has to be assignable to the inherited one. Adding a key is clean and narrowing works, but widening raises
TS2430on the declaration file, whichskipLibCheck: truesilences.Changelog:
[GENERAL] [CHANGED] - Allow module augmentation to extend generated props and style types
Test Plan:
yarn build-types: all 24 annotated types now emit an empty interface body.ViewStyle,TextStyleandImageStyleare unchanged; the props types gain the 11<Name>Corealiases.Compiled augmentations with
skipLibCheck: false. Styles: the two lines above pass here and reportTS2353onmain. Props: adding a key and narrowing an existing one on each of the 11 types passes here and reportsTS2717onmain.yarn flow-check,yarn test-generated-typescript,yarn format-checkandyarn lint: clean, apart from 3 Flow errors inpackages/react-native-codegen/libalready onmain.yarn jest packages/react-native/Libraries packages/react-native/src scripts/js-api: 632 tests pass, no snapshot changed.