Conversation
|
@huntie has exported this pull request. If you are a Meta employee, you can view the originating Diff in D104808984. |
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
Summary: #### Motivation Adds (preserves) compatibility of Nativewind and Expo Web type augmentations with the Strict TypeScript API. - These libraries rely on key React Native component types being defined as `interface`, not `type`, since TS module augmentation only supports `interface` declarations. - Previously, our opt-in generated TypeScript types (Strict TypeScript API) emitted all props types as `type Foo = Readonly<...>` ), matching Flow source. However, this API change vs our manual types (which predominantly used `interface` on props) breaks library compatibility in these cases. - This is very awkward to otherwise solve in user space — so opt for backwards compatibility in our new types. #### Primer TypeScript module augmentation lets a library extend an existing module's types without modifying the source. e.g. In Nativewind ([source](https://www.nativewind.dev/docs/guides/third-party-components)): ```ts declare module 'react-native' { interface ScrollViewProps extends ViewProps, ScrollViewPropsIOS, ScrollViewPropsAndroid, Touchable { contentContainerClassName?: string; indicatorClassName?: string; } interface FlatListProps<ItemT> extends VirtualizedListProps<ItemT> { columnWrapperClassName?: string; } interface ViewProps { className?: string; } } ``` Expo's `react-native-web.d.ts` ([source](https://unpkg.com/expo@54.0.31/types/react-native-web.d.ts)) also follows the same pattern across several component props types. #### Changes Add new `build-types` transform, implementing an opt-in `/** build-types emit-as-interface */` annotation, converting eligible `type` aliases to `interface` declarations. - Changing the Flow source files directly isn't viable — Flow doesn't support `interface extends Omit<>`, and several of these types use `Omit<>` in their composition. The post-transform operates on the TypeScript output where `interface extends Readonly<Omit<...>>` is valid. The following emitted types are updated: | Type | Augmented by | Source | |---|---|---| | `ViewProps` | `className?` | [Nativewind](https://www.nativewind.dev/docs/guides/third-party-components), [Expo](https://unpkg.com/expo@54.0.31/types/react-native-web.d.ts) | | `ScrollViewProps` | `contentContainerClassName?`, `indicatorClassName?` | [Nativewind](https://www.nativewind.dev/docs/guides/third-party-components) | | `ImagePropsBase` | `className?` | [Expo](https://unpkg.com/expo@54.0.31/types/react-native-web.d.ts) | | `SwitchProps` | `className?` | [Expo](https://unpkg.com/expo@54.0.31/types/react-native-web.d.ts) | | `TouchableWithoutFeedbackProps` | `className?` | [Expo](https://unpkg.com/expo@54.0.31/types/react-native-web.d.ts) | | `InputAccessoryViewProps` | `className?` | [Expo](https://unpkg.com/expo@54.0.31/types/react-native-web.d.ts) | `FlatListProps` is not included in this PR: its bare intersection (no `Readonly<>` wrapper) has a conflicting `fadingEdgeLength` property across constituent types that cannot be expressed as a single `extends` clause without hitting TS2320. This will be addressed in a follow-up. `VirtualizedListWithoutRenderItemProps<T>` in `react-native/virtualized-lists` is separately owned and not changed here. Changelog: [General][Changed] - **Strict TypeScript API**: Select component props types are now `interface` declarations, enabling module augmentation by libraries like NativeWind and Expo (preserve compatibility) Differential Revision: D104808984
Collaborator
|
This pull request was successfully merged by @huntie in db89600 When will my fix make it into a release? | How to file a pick request? |
|
This pull request has been merged in db89600. |
meta-codesync Bot
pushed a commit
that referenced
this pull request
Aug 27, 2026
Summary: In response to this comment: #57490 (comment) The DefinitelyTyped `react-native-web` types augment the `react-native` module to layer web-only props and style values onto React Native's types. Module augmentation only works against `interface` declarations, so these hit `error TS2300: Duplicate identifier`. This was solved in #56809 — this diff extends `interface` emission to additional types as below. **Changes** Annotate the remaining types that `types/react-native-web` augments with `build-types emit-as-interface`: - `AccessibilityProps` - `ImageProps` - `PressableStateCallbackType` - `ViewStyle`, `TextStyle`, `ImageStyle` **Source for matched `types/react-native-web` conflicts** | Type | Declared in | Augmented by `types/react-native-web` | | --- | --- | --- | | `AccessibilityProps` | `Libraries/Components/View/ViewAccessibility.js:342` | [index.d.ts#L1272](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1272) | | `ImageProps` | `Libraries/Image/ImageProps.js:336` | [index.d.ts#L1422](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1422) | | `PressableStateCallbackType` | `Libraries/Components/Pressable/Pressable.js:36` | [index.d.ts#L1444](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1444) | | `ViewStyle` | `Libraries/StyleSheet/StyleSheet.js.flow:141` | [index.d.ts#L1458](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1458) | | `TextStyle` | `Libraries/StyleSheet/StyleSheet.js.flow:159` | [index.d.ts#L1486](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1486) | | `ImageStyle` | `Libraries/StyleSheet/StyleSheet.js.flow:177` | [index.d.ts#L1514](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1514) | **Not fixed** The remaining DT failures (parsed from https://github.com/DefinitelyTyped/DefinitelyTyped/actions/runs/32138113480) aren't interface issues: - `InteractionManager` has no export in the Strict API at all. - `VirtualizedListProps` is genuinely non-generic in the Flow source (`packages/virtualized-lists/Lists/VirtualizedListProps.js:287`), and `getItem` / `getItemCount` are required there. DT's `VirtualizedListProps<ItemT>` with those omitted is an assumption carried over from the old hand-written types. - The `ViewStyle` / `TextStyle` / `ImageStyle` "incorrectly extends `WebStyle`" errors **will persist**. RN's `DimensionValue` includes `null`, and DT redefines `bottom?: CSSProperties["bottom"] | DimensionValue` on an interface extending `WebStyle`, whose `bottom` does not accept `null`. DT needs `Exclude<DimensionValue, null>` there. Expect 3 of the 16 reported errors to remain once the duplicate-identifier ones clear. cc rjbailey Changelog: [General][Fixed] - **JS API**: Additional Props/Style types are now defined as `interface`, fixing compatibility with certain DefinitelyTyped packages Pull Request resolved: #58062 Test Plan: - `node ./scripts/js-api/build-types` — snapshot regenerated; `--validate` passes - `yarn test-generated-typescript`, `yarn test-typescript` — pass - `yarn jest scripts/js-api` — 141 tests pass - Scratch project replaying react-native-web's augmentations against `types_generated`: all six now merge cleanly. As a control, augmenting `ImagePropsAndroid` (still a type alias) in the same harness reproduces `error TS2300: Duplicate identifier`, confirming the harness detects the failure mode. Reviewed By: cipolleschi Differential Revision: D117534044 Pulled By: cortinico fbshipit-source-id: 8fc37375f7a3d9ea86e1a206059d365b38658231
shashikant-panchal
pushed a commit
to shashikant-panchal/react-native
that referenced
this pull request
Sep 10, 2026
Summary: In response to this comment: react#57490 (comment) The DefinitelyTyped `react-native-web` types augment the `react-native` module to layer web-only props and style values onto React Native's types. Module augmentation only works against `interface` declarations, so these hit `error TS2300: Duplicate identifier`. This was solved in react#56809 — this diff extends `interface` emission to additional types as below. **Changes** Annotate the remaining types that `types/react-native-web` augments with `build-types emit-as-interface`: - `AccessibilityProps` - `ImageProps` - `PressableStateCallbackType` - `ViewStyle`, `TextStyle`, `ImageStyle` **Source for matched `types/react-native-web` conflicts** | Type | Declared in | Augmented by `types/react-native-web` | | --- | --- | --- | | `AccessibilityProps` | `Libraries/Components/View/ViewAccessibility.js:342` | [index.d.ts#L1272](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1272) | | `ImageProps` | `Libraries/Image/ImageProps.js:336` | [index.d.ts#L1422](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1422) | | `PressableStateCallbackType` | `Libraries/Components/Pressable/Pressable.js:36` | [index.d.ts#L1444](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1444) | | `ViewStyle` | `Libraries/StyleSheet/StyleSheet.js.flow:141` | [index.d.ts#L1458](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1458) | | `TextStyle` | `Libraries/StyleSheet/StyleSheet.js.flow:159` | [index.d.ts#L1486](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1486) | | `ImageStyle` | `Libraries/StyleSheet/StyleSheet.js.flow:177` | [index.d.ts#L1514](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df17ec34853e80dac955a0c2649cec989d90b2b5/types/react-native-web/index.d.ts#L1514) | **Not fixed** The remaining DT failures (parsed from https://github.com/DefinitelyTyped/DefinitelyTyped/actions/runs/32138113480) aren't interface issues: - `InteractionManager` has no export in the Strict API at all. - `VirtualizedListProps` is genuinely non-generic in the Flow source (`packages/virtualized-lists/Lists/VirtualizedListProps.js:287`), and `getItem` / `getItemCount` are required there. DT's `VirtualizedListProps<ItemT>` with those omitted is an assumption carried over from the old hand-written types. - The `ViewStyle` / `TextStyle` / `ImageStyle` "incorrectly extends `WebStyle`" errors **will persist**. RN's `DimensionValue` includes `null`, and DT redefines `bottom?: CSSProperties["bottom"] | DimensionValue` on an interface extending `WebStyle`, whose `bottom` does not accept `null`. DT needs `Exclude<DimensionValue, null>` there. Expect 3 of the 16 reported errors to remain once the duplicate-identifier ones clear. cc rjbailey Changelog: [General][Fixed] - **JS API**: Additional Props/Style types are now defined as `interface`, fixing compatibility with certain DefinitelyTyped packages Pull Request resolved: react#58062 Test Plan: - `node ./scripts/js-api/build-types` — snapshot regenerated; `--validate` passes - `yarn test-generated-typescript`, `yarn test-typescript` — pass - `yarn jest scripts/js-api` — 141 tests pass - Scratch project replaying react-native-web's augmentations against `types_generated`: all six now merge cleanly. As a control, augmenting `ImagePropsAndroid` (still a type alias) in the same harness reproduces `error TS2300: Duplicate identifier`, confirming the harness detects the failure mode. Reviewed By: cipolleschi Differential Revision: D117534044 Pulled By: cortinico fbshipit-source-id: 8fc37375f7a3d9ea86e1a206059d365b38658231
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:
Motivation
Adds (preserves) compatibility of Nativewind and Expo Web type augmentations with the Strict TypeScript API.
interface, nottype, since TS module augmentation only supportsinterfacedeclarations.type Foo = Readonly<...>), matching Flow source. However, this API change vs our manual types (which predominantly usedinterfaceon props) breaks library compatibility in these cases.Primer
TypeScript module augmentation lets a library extend an existing module's types without modifying the source.
e.g. In Nativewind (source):
Expo's
react-native-web.d.ts(source) also follows the same pattern across several component props types.Changes
Add new
build-typestransform, implementing an opt-in/** build-types emit-as-interface */annotation, converting eligibletypealiases tointerfacedeclarations.interface extends Omit<>, and several of these types useOmit<>in their composition. The post-transform operates on the TypeScript output whereinterface extends Readonly<Omit<...>>is valid.The following emitted types are updated:
ViewPropsclassName?ScrollViewPropscontentContainerClassName?,indicatorClassName?ImagePropsBaseclassName?SwitchPropsclassName?TouchableWithoutFeedbackPropsclassName?InputAccessoryViewPropsclassName?FlatListPropsis not included in this PR: its bare intersection (noReadonly<>wrapper) has a conflictingfadingEdgeLengthproperty across constituent types that cannot be expressed as a singleextendsclause without hitting TS2320. This will be addressed in a follow-up.VirtualizedListWithoutRenderItemProps<T>inreact-native/virtualized-listsis separately owned and not changed here.Changelog:
[General][Changed] - Strict TypeScript API: Select component props types are now
interfacedeclarations, enabling module augmentation by libraries like NativeWind and Expo (preserve compatibility)Differential Revision: D104808984