Skip to content

Commit 0259d3c

Browse files
coadofacebook-github-bot
authored andcommitted
Fix generated types base on __typetests__ (facebook#51317)
Summary: This diff is a set of alignments/improvements in generated TS types. It includes: - extending `AppStateStatus` with `extension` and `unknown`, - exporting `AnimatedProps` under Animated namespace, - resolving issue with discriminated unions in `ProgressBarAndroidTypes`, - fixing `StyleSheet.create` type to accept only specified style properties, - extending `TextProps` with `AccessibilityProps`, - extending Fn `Args` generic with `$ReadOnlyArray` in `ErrorUtils`, - small `__typetests__` adjustments, - removing type test `styleDimensionValueValidAnimated` as `DimensionValue` no longer accepts `AnimatedNode` , - removing `styleDimensionValueInvalid` as `DimensionValue` accepts any string now - template literal types in Flow are not supported, - changing `overlayColor` type to `ColorValue` to align with manual types, - fixing `AnimatedPropsAllowlist` type which wasn't correct in TS because index signature type was different from style type, - using `DeviceEventEmitter` instead of `DeviceEventEmitterStatic` in type tests which is equivalent in both new and old types - `DeviceEventEmitterStatic` was only a type of `DeviceEventEmitter`, - removing type test for checking forwarded key type - doesn't work with new types and that shouldn't be supported, - removing `Animated.legacyRef` type test - not included in new types, - adding `DOMRect` from "dom" lib to globals.d.ts to not include "dom" lib in the tsconfig - tries to compare globals with lib.dom.d.ts and produces many errors, - exporting `SectionListData` , - bumping `definitelytyped/dtslint` to 0.0.178 version which removes `testNoTsIgnore` check [here](microsoft/DefinitelyTyped-tools@0e0838a) Changelog: [Internal] Reviewed By: huntie Differential Revision: D74246304
1 parent ca764bb commit 0259d3c

File tree

21 files changed

+222
-191
lines changed

21 files changed

+222
-191
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@babel/plugin-transform-regenerator": "^7.24.7",
5151
"@babel/preset-env": "^7.25.3",
5252
"@babel/preset-flow": "^7.24.7",
53-
"@definitelytyped/dtslint": "^0.0.127",
53+
"@definitelytyped/dtslint": "^0.0.178",
5454
"@jest/create-cache-key-function": "^29.7.0",
5555
"@react-native/metro-babel-transformer": "0.80.0-main",
5656
"@react-native/metro-config": "0.80.0-main",

packages/react-native/Libraries/Animated/AnimatedExports.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export type {default as AnimatedDivision} from './nodes/AnimatedDivision';
3737
export type {default as AnimatedModulo} from './nodes/AnimatedModulo';
3838
export type {default as AnimatedMultiplication} from './nodes/AnimatedMultiplication';
3939
export type {default as AnimatedSubtraction} from './nodes/AnimatedSubtraction';
40-
export type {WithAnimatedValue} from './createAnimatedComponent';
40+
export type {WithAnimatedValue, AnimatedProps} from './createAnimatedComponent';
4141
export type {AnimatedComponentType as AnimatedComponent} from './createAnimatedComponent';
4242

4343
/**

packages/react-native/Libraries/Animated/nodes/AnimatedProps.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import invariant from 'invariant';
2222

2323
export type AnimatedPropsAllowlist = $ReadOnly<{
2424
style?: ?AnimatedStyleAllowlist,
25-
[string]: true,
25+
[key: string]: true | AnimatedStyleAllowlist,
2626
}>;
2727

2828
type TargetView = {

packages/react-native/Libraries/AppState/AppState.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ import NativeAppState from './NativeAppState';
2222
* - @platform android - on another Activity (even if it was launched by your app)
2323
* @platform ios - inactive - This is a state that occurs when transitioning between foreground & background, and during periods of inactivity such as entering the multitasking view, opening the Notification Center or in the event of an incoming call.
2424
*/
25-
export type AppStateStatus = 'inactive' | 'background' | 'active';
25+
export type AppStateStatus =
26+
| 'inactive'
27+
| 'background'
28+
| 'active'
29+
| 'extension'
30+
| 'unknown';
2631

2732
/**
2833
* change - This even is received when the app state has changed.

packages/react-native/Libraries/Components/ActivityIndicator/ActivityIndicator.js

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const ActivityIndicator = (
110110
style={StyleSheet.compose(styles.container, style)}>
111111
{Platform.OS === 'android' ? (
112112
// $FlowFixMe[prop-missing] Flow doesn't know when this is the android component
113+
// $FlowFixMe[incompatible-type]
113114
<PlatformActivityIndicator {...nativeProps} {...androidProps} />
114115
) : (
115116
/* $FlowFixMe[incompatible-type] (>=0.106.0 site=react_native_android_fb) This comment

packages/react-native/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ import Platform from '../../Utilities/Platform';
1717

1818
export type {ProgressBarAndroidProps};
1919

20+
// A utility type to preserve the semantics of the union uses in the definition
21+
// of ProgressBarAndroidProps. TS's Omit does not distribute over unions, so
22+
// we define our own version which does. This does not affect Flow.
23+
// $FlowExpectedError[unclear-type]
24+
type Omit<T, K> = T extends any ? Pick<T, Exclude<$Keys<T>, K>> : T;
25+
2026
/**
2127
* ProgressBarAndroid has been extracted from react-native core and will be removed in a future release.
2228
* It can now be installed and imported from `@react-native-community/progress-bar-android` instead of 'react-native'.
@@ -27,7 +33,7 @@ let ProgressBarAndroid: component(
2733
ref?: React.RefSetter<
2834
React.ElementRef<ProgressBarAndroidNativeComponentType>,
2935
>,
30-
...props: ProgressBarAndroidProps
36+
...props: Omit<ProgressBarAndroidProps, empty>
3137
);
3238

3339
if (Platform.OS === 'android') {

packages/react-native/Libraries/Components/ProgressBarAndroid/ProgressBarAndroidTypes.js

+29-20
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,25 @@ import type {ViewProps} from '../View/ViewPropTypes';
1717
* `indeterminate` can only be false if `styleAttr` is Horizontal, and requires a
1818
* `progress` value.
1919
*/
20-
type ProgressBarAndroidStyleAttrProp =
21-
| {
22-
styleAttr: 'Horizontal',
23-
indeterminate: false,
24-
progress: number,
25-
}
26-
| {
27-
styleAttr:
28-
| 'Horizontal'
29-
| 'Normal'
30-
| 'Small'
31-
| 'Large'
32-
| 'Inverse'
33-
| 'SmallInverse'
34-
| 'LargeInverse',
35-
indeterminate: true,
36-
};
20+
type DeterminateProgressBarAndroidStyleAttrProp = {
21+
styleAttr: 'Horizontal',
22+
indeterminate: false,
23+
progress: number,
24+
};
3725

38-
export type ProgressBarAndroidProps = $ReadOnly<{
39-
...ViewProps,
40-
...ProgressBarAndroidStyleAttrProp,
26+
type IndeterminateProgressBarAndroidStyleAttrProp = {
27+
styleAttr:
28+
| 'Horizontal'
29+
| 'Normal'
30+
| 'Small'
31+
| 'Large'
32+
| 'Inverse'
33+
| 'SmallInverse'
34+
| 'LargeInverse',
35+
indeterminate: true,
36+
};
4137

38+
type ProgressBarAndroidBaseProps = $ReadOnly<{
4239
/**
4340
* Whether to show the ProgressBar (true, the default) or hide it (false).
4441
*/
@@ -52,3 +49,15 @@ export type ProgressBarAndroidProps = $ReadOnly<{
5249
*/
5350
testID?: ?string,
5451
}>;
52+
53+
export type ProgressBarAndroidProps =
54+
| $ReadOnly<{
55+
...ViewProps,
56+
...ProgressBarAndroidBaseProps,
57+
...DeterminateProgressBarAndroidStyleAttrProp,
58+
}>
59+
| $ReadOnly<{
60+
...ViewProps,
61+
...ProgressBarAndroidBaseProps,
62+
...IndeterminateProgressBarAndroidStyleAttrProp,
63+
}>;

packages/react-native/Libraries/EventEmitter/NativeEventEmitter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class NativeEventEmitter<
5252
{
5353
_nativeModule: ?NativeModule;
5454

55-
constructor(nativeModule: ?NativeModule) {
55+
constructor(nativeModule?: ?NativeModule) {
5656
if (Platform.OS === 'ios') {
5757
invariant(
5858
nativeModule != null,

packages/react-native/Libraries/StyleSheet/StyleSheetExports.js.flow

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,6 @@ declare export const setStyleAttributePreprocessor: (
107107
* An identity function for creating style sheets.
108108
*/
109109
// $FlowFixMe[unsupported-variance-annotation]
110-
declare export const create: <+S: ____Styles_Internal>(obj: S) => $ReadOnly<S>;
110+
declare export const create: <+S: ____Styles_Internal>(
111+
obj: S & ____Styles_Internal,
112+
) => $ReadOnly<S>;

packages/react-native/Libraries/StyleSheet/StyleSheetTypes.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
____ViewStyle_InternalOverrides,
2222
} from './private/_StyleSheetTypesOverrides';
2323
import type {____TransformStyle_Internal} from './private/_TransformStyle';
24+
import type {ColorValue} from './StyleSheet';
2425

2526
export type {____TransformStyle_Internal};
2627

@@ -1001,7 +1002,7 @@ export type ____ImageStyle_InternalCore = $ReadOnly<{
10011002
resizeMode?: ImageResizeMode,
10021003
objectFit?: 'cover' | 'contain' | 'fill' | 'scale-down' | 'none',
10031004
tintColor?: ____ColorValue_Internal,
1004-
overlayColor?: string,
1005+
overlayColor?: ColorValue,
10051006
overflow?: 'visible' | 'hidden',
10061007
}>;
10071008

@@ -1015,7 +1016,7 @@ export type ____DangerouslyImpreciseStyle_InternalCore = $ReadOnly<{
10151016
resizeMode?: ImageResizeMode,
10161017
objectFit?: 'cover' | 'contain' | 'fill' | 'scale-down' | 'none',
10171018
tintColor?: ____ColorValue_Internal,
1018-
overlayColor?: string,
1019+
overlayColor?: ColorValue,
10191020
}>;
10201021

10211022
export type ____DangerouslyImpreciseStyle_Internal = $ReadOnly<{

packages/react-native/Libraries/Text/TextProps.js

+2-31
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import type {
1414
AccessibilityActionEvent,
1515
AccessibilityActionInfo,
16+
AccessibilityProps,
1617
AccessibilityRole,
1718
AccessibilityState,
1819
Role,
@@ -124,20 +125,7 @@ export type TextPropsAndroid = {
124125
};
125126

126127
type TextBaseProps = $ReadOnly<{
127-
/**
128-
* Indicates whether the view is an accessibility element.
129-
*
130-
* See https://reactnative.dev/docs/text#accessible
131-
*/
132-
accessible?: ?boolean,
133-
accessibilityActions?: ?$ReadOnlyArray<AccessibilityActionInfo>,
134128
onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed,
135-
accessibilityHint?: ?Stringish,
136-
accessibilityLanguage?: ?Stringish,
137-
accessibilityLabel?: ?Stringish,
138-
accessibilityRole?: ?AccessibilityRole,
139-
accessibilityState?: ?AccessibilityState,
140-
'aria-label'?: ?string,
141129

142130
/**
143131
* Whether fonts should scale to respect Text Size accessibility settings.
@@ -152,24 +140,6 @@ type TextBaseProps = $ReadOnly<{
152140
*
153141
*/
154142
android_hyphenationFrequency?: ?('normal' | 'none' | 'full'),
155-
156-
/**
157-
* alias for accessibilityState
158-
*
159-
* see https://reactnative.dev/docs/accessibility#accessibilitystate
160-
*/
161-
'aria-busy'?: ?boolean,
162-
'aria-checked'?: ?boolean | 'mixed',
163-
'aria-disabled'?: ?boolean,
164-
'aria-expanded'?: ?boolean,
165-
'aria-selected'?: ?boolean,
166-
167-
/**
168-
* Represents the nativeID of the associated label text. When the assistive technology focuses on the component with this props, the text is read aloud.
169-
* This prop is listed for cross-platform reasons and has no real effect on Android or iOS.
170-
*/
171-
'aria-labelledby'?: ?string,
172-
173143
children?: ?React.Node,
174144

175145
/**
@@ -306,4 +276,5 @@ export type TextProps = $ReadOnly<{
306276
...TextPropsIOS,
307277
...TextPropsAndroid,
308278
...TextBaseProps,
279+
...AccessibilityProps,
309280
}>;

0 commit comments

Comments
 (0)