Repository navigation
Commit 3ccf6a0
Make legacy TypeScript ImageStyle extend ViewStyle (#58907)
Summary:
## Motivation
Projects on the default legacy TypeScript types get type errors when they set valid style props on `<Image>`. This is coming from [issue](#52957)
## What is the Issue About?
It reports that `filter`, `boxShadow`, `mixBlendMode`, `borderTopStartRadius` and `outlineColor` props give TS error. These props are already accepted by the opt-in strict API types.
## Background
React Native ships two sets of TypeScript style types:
- **Legacy (default):** hand-written in `types_DEPRECATED/Libraries/StyleSheet/StyleSheetTypes.d.ts`. Maintained by hand, so it drifts.
- **Strict API (opt-in):** generated from the Flow source of truth, `Libraries/StyleSheet/StyleSheetTypes.js`, so it cannot drift.
## Root Cause
In Flow, `ImageStyle` spreads `ViewStyle` and only narrows `overflow` to `visible | hidden`. The legacy `ImageStyle` instead extended `FlexStyle`/`ShadowStyleIOS`/`TransformsStyle` and redeclared a hand-picked subset of view props, so it rejected 37 `ViewStyle` props:
- Border and outline colours: `borderTopColor`, `borderBottomColor`, `borderLeftColor`, `borderRightColor`, `borderStartColor`, `borderEndColor`, `borderBlockColor`, `borderBlockStartColor`, `borderBlockEndColor`, `outlineColor`
- Logical corner radii: `borderTopStartRadius`, `borderTopEndRadius`, `borderBottomStartRadius`, `borderBottomEndRadius`, `borderStartStartRadius`, `borderStartEndRadius`, `borderEndStartRadius`, `borderEndEndRadius`
- `borderCurve`, `borderStyle`, `outlineStyle`, `outlineWidth`, `outlineOffset`, `elevation`, `pointerEvents`, `isolation`, `boxShadow`, `filter`, `mixBlendMode`
- Background layers: `backgroundImage`, `backgroundSize`, `backgroundPosition`, `backgroundRepeat` and their `experimental_` versions
`TextStyle` already extends `ViewStyle`, so it is not affected.
## Description of Changes
- `ImageStyle` now extends `ViewStyle`, narrows `overflow` to `visible | hidden`, and keeps only the Image-specific props (`resizeMode`, `overlayColor`, `tintColor`, `objectFit`). The 10 view props it used to redeclare are now inherited with identical types. New `ViewStyle` props flow through automatically, as they already do for `TextStyle` and for the generated types.
- The type test `__typetests__/stylesheet-style-props.tsx` (renamed from the earlier issue reproducer) sets all 37 props on an Image style. It asserts that `ImageStyle` and `TextStyle` declare every `ViewStyle` key, so future drift fails CI with the missing prop names. Negative checks confirm `ImageStyle` still rejects `overflow: "scroll"` and text-only props.
The change only widens what `ImageStyle` accepts, matching the generated types.
Changelog:
[General][Fixed] - Fix the legacy TypeScript `ImageStyle` type rejecting valid `ViewStyle` props such as `filter`, `boxShadow` and `mixBlendMode`
Differential Revision: D1230032371 parent df5aa64 commit 3ccf6a0
2 files changed
Lines changed: 105 additions & 11 deletions
File tree
- packages/react-native
- __typetests__
- types_DEPRECATED/Libraries/StyleSheet
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
649 | 649 | | |
650 | 650 | | |
651 | 651 | | |
652 | | - | |
| 652 | + | |
653 | 653 | | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | 654 | | |
663 | 655 | | |
664 | 656 | | |
665 | | - | |
666 | 657 | | |
667 | | - | |
668 | 658 | | |
0 commit comments