Skip to content

Commit f41f3bf

Browse files
marcoww6meta-codesync[bot]
authored andcommitted
Transform all Flow legacy utility types ($NonMaybeType) to TypeScript-style types in xplat/js (#54935)
Summary: Pull Request resolved: #54935 We are transforming the following utility types to be more consistent with typescript and better AI integration: * `$NonMaybeType` -> `NonNullable` * `$ReadOnly` -> `Readonly` * `$ReadOnlyArray` -> `ReadonlyArray` * `$ReadOnlyMap` -> `ReadonlyMap` * `$ReadOnlySet` -> `ReadonlySet` * `$Keys` -> `keyof` * `$Values` -> `Values` * `mixed` -> `unknown` See details in https://fb.workplace.com/groups/flowlang/permalink/1837907750148213/. drop-conflicts Reviewed By: gkz Differential Revision: D89494075 fbshipit-source-id: 1bc3e0039dfb5bf04f1860d5098e024fb8491647
1 parent 68b0c2a commit f41f3bf

11 files changed

Lines changed: 219 additions & 243 deletions

File tree

packages/dev-middleware/src/inspector-proxy/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export type PageFromDevice = $ReadOnly<{
5656

5757
export type Page = $ReadOnly<{
5858
...PageFromDevice,
59-
capabilities: $NonMaybeType<PageFromDevice['capabilities']>,
59+
capabilities: NonNullable<PageFromDevice['capabilities']>,
6060
}>;
6161

6262
// Chrome Debugger Protocol message/event passed between device and debugger.

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

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ type TextInputStateType = $ReadOnly<{
149149
blurTextInput: (textField: ?HostInstance) => void,
150150
}>;
151151

152-
type ViewCommands = $NonMaybeType<
152+
type ViewCommands = NonNullable<
153153
| typeof AndroidTextInputCommands
154154
| typeof RCTMultilineTextInputNativeCommands
155155
| typeof RCTSinglelineTextInputNativeCommands,
@@ -188,8 +188,8 @@ function useTextInputStateSynchronization({
188188
const [lastNativeText, setLastNativeText] = useState<?Stringish>(props.value);
189189
const [lastNativeSelectionState, setLastNativeSelection] =
190190
useState<LastNativeSelection>({
191-
selection: {start: -1, end: -1},
192-
mostRecentEventCount: mostRecentEventCount,
191+
mostRecentEventCount,
192+
selection: {end: -1, start: -1},
193193
});
194194

195195
const lastNativeSelection = lastNativeSelectionState.selection;
@@ -212,7 +212,7 @@ function useTextInputStateSynchronization({
212212
lastNativeSelection.end !== selection.end)
213213
) {
214214
nativeUpdate.selection = selection;
215-
setLastNativeSelection({selection, mostRecentEventCount});
215+
setLastNativeSelection({mostRecentEventCount, selection});
216216
}
217217

218218
if (Object.keys(nativeUpdate).length === 0) {
@@ -240,7 +240,7 @@ function useTextInputStateSynchronization({
240240
viewCommands,
241241
]);
242242

243-
return {setLastNativeText, setLastNativeSelection};
243+
return {setLastNativeSelection, setLastNativeText};
244244
}
245245

246246
/**
@@ -377,8 +377,8 @@ function InternalTextInput(props: TextInputProps): React.Node {
377377
propsSelection == null
378378
? null
379379
: {
380-
start: propsSelection.start,
381380
end: propsSelection.end ?? propsSelection.start,
381+
start: propsSelection.start,
382382
};
383383

384384
const text =
@@ -397,9 +397,9 @@ function InternalTextInput(props: TextInputProps): React.Node {
397397
const [mostRecentEventCount, setMostRecentEventCount] = useState<number>(0);
398398
const {setLastNativeText, setLastNativeSelection} =
399399
useTextInputStateSynchronization({
400-
props,
401400
inputRef,
402401
mostRecentEventCount,
402+
props,
403403
selection,
404404
text,
405405
viewCommands,
@@ -469,13 +469,13 @@ function InternalTextInput(props: TextInputProps): React.Node {
469469
);
470470
}
471471
},
472+
getNativeRef(): ?TextInputInstance {
473+
return inputRef.current;
474+
},
472475
// TODO: Fix this returning true on null === null, when no input is focused
473476
isFocused(): boolean {
474477
return TextInputState.currentlyFocusedInput() === inputRef.current;
475478
},
476-
getNativeRef(): ?TextInputInstance {
477-
return inputRef.current;
478-
},
479479
setSelection(start: number, end: number): void {
480480
if (inputRef.current != null) {
481481
viewCommands.setTextAndSelection(
@@ -525,8 +525,8 @@ function InternalTextInput(props: TextInputProps): React.Node {
525525
}
526526

527527
setLastNativeSelection({
528-
selection: event.nativeEvent.selection,
529528
mostRecentEventCount,
529+
selection: event.nativeEvent.selection,
530530
});
531531
};
532532

@@ -590,6 +590,7 @@ function InternalTextInput(props: TextInputProps): React.Node {
590590

591591
const config = useMemo(
592592
() => ({
593+
cancelable: Platform.OS === 'ios' ? !rejectResponderTermination : null,
593594
hitSlop,
594595
onPress: (event: GestureResponderEvent) => {
595596
onPress?.(event);
@@ -599,9 +600,8 @@ function InternalTextInput(props: TextInputProps): React.Node {
599600
}
600601
}
601602
},
602-
onPressIn: onPressIn,
603-
onPressOut: onPressOut,
604-
cancelable: Platform.OS === 'ios' ? !rejectResponderTermination : null,
603+
onPressIn,
604+
onPressOut,
605605
}),
606606
[
607607
editable,
@@ -740,12 +740,12 @@ function InternalTextInput(props: TextInputProps): React.Node {
740740
}
741741
// For consistency with iOS set cursor/selectionHandle color as selectionColor
742742
const colorProps = {
743+
cursorColor: cursorColor === undefined ? selectionColor : cursorColor,
743744
selectionColor,
744745
selectionHandleColor:
745746
selectionHandleColor === undefined
746747
? selectionColor
747748
: selectionHandleColor,
748-
cursorColor: cursorColor === undefined ? selectionColor : cursorColor,
749749
};
750750
textInput = (
751751
/* $FlowFixMe[prop-missing] the types for AndroidTextInput don't match up
@@ -799,8 +799,8 @@ function InternalTextInput(props: TextInputProps): React.Node {
799799
}
800800

801801
const enterKeyHintToReturnTypeMap = {
802-
enter: 'default',
803802
done: 'done',
803+
enter: 'default',
804804
go: 'go',
805805
next: 'next',
806806
previous: 'previous',
@@ -809,19 +809,20 @@ const enterKeyHintToReturnTypeMap = {
809809
} as const;
810810

811811
const inputModeToKeyboardTypeMap = {
812-
none: 'default',
813-
text: 'default',
814812
decimal: 'decimal-pad',
813+
email: 'email-address',
814+
none: 'default',
815815
numeric: 'number-pad',
816-
tel: 'phone-pad',
817816
search:
818817
Platform.OS === 'ios' ? ('web-search' as const) : ('default' as const),
819-
email: 'email-address',
818+
tel: 'phone-pad',
819+
text: 'default',
820820
url: 'url',
821821
} as const;
822822

823823
// Map HTML autocomplete values to Android autoComplete values
824824
const autoCompleteWebToAutoCompleteAndroidMap = {
825+
'additional-name': 'name-middle',
825826
'address-line1': 'postal-address-region',
826827
'address-line2': 'postal-address-locality',
827828
bday: 'birthdate-full',
@@ -836,12 +837,11 @@ const autoCompleteWebToAutoCompleteAndroidMap = {
836837
country: 'postal-address-country',
837838
'current-password': 'password',
838839
email: 'email',
840+
'family-name': 'name-family',
841+
'given-name': 'name-given',
839842
'honorific-prefix': 'name-prefix',
840843
'honorific-suffix': 'name-suffix',
841844
name: 'name',
842-
'additional-name': 'name-middle',
843-
'family-name': 'name-family',
844-
'given-name': 'name-given',
845845
'new-password': 'password-new',
846846
off: 'off',
847847
'one-time-code': 'sms-otp',
@@ -856,33 +856,33 @@ const autoCompleteWebToAutoCompleteAndroidMap = {
856856

857857
// Map HTML autocomplete values to iOS textContentType values
858858
const autoCompleteWebToTextContentTypeMap = {
859+
'additional-name': 'middleName',
859860
'address-line1': 'streetAddressLine1',
860861
'address-line2': 'streetAddressLine2',
861862
bday: 'birthdate',
862863
'bday-day': 'birthdateDay',
863864
'bday-month': 'birthdateMonth',
864865
'bday-year': 'birthdateYear',
866+
'cc-additional-name': 'creditCardMiddleName',
865867
'cc-csc': 'creditCardSecurityCode',
868+
'cc-exp': 'creditCardExpiration',
866869
'cc-exp-month': 'creditCardExpirationMonth',
867870
'cc-exp-year': 'creditCardExpirationYear',
868-
'cc-exp': 'creditCardExpiration',
869-
'cc-given-name': 'creditCardGivenName',
870-
'cc-additional-name': 'creditCardMiddleName',
871871
'cc-family-name': 'creditCardFamilyName',
872+
'cc-given-name': 'creditCardGivenName',
872873
'cc-name': 'creditCardName',
873874
'cc-number': 'creditCardNumber',
874875
'cc-type': 'creditCardType',
875-
'current-password': 'password',
876876
country: 'countryName',
877+
'current-password': 'password',
877878
email: 'emailAddress',
878-
name: 'name',
879-
'additional-name': 'middleName',
880879
'family-name': 'familyName',
881880
'given-name': 'givenName',
882-
nickname: 'nickname',
883881
'honorific-prefix': 'namePrefix',
884882
'honorific-suffix': 'nameSuffix',
883+
name: 'name',
885884
'new-password': 'newPassword',
885+
nickname: 'nickname',
886886
off: 'none',
887887
'one-time-code': 'oneTimeCode',
888888
organization: 'organizationName',
@@ -959,11 +959,10 @@ TextInput.displayName = 'TextInput';
959959

960960
// $FlowFixMe[prop-missing]
961961
TextInput.State = {
962-
currentlyFocusedInput: TextInputState.currentlyFocusedInput,
963-
962+
blurTextInput: TextInputState.blurTextInput,
964963
currentlyFocusedField: TextInputState.currentlyFocusedField,
964+
currentlyFocusedInput: TextInputState.currentlyFocusedInput,
965965
focusTextInput: TextInputState.focusTextInput,
966-
blurTextInput: TextInputState.blurTextInput,
967966
};
968967

969968
export type TextInputComponentStatics = $ReadOnly<{
@@ -981,9 +980,9 @@ const styles = StyleSheet.create({
981980

982981
const verticalAlignToTextAlignVerticalMap = {
983982
auto: 'auto',
984-
top: 'top',
985983
bottom: 'bottom',
986984
middle: 'center',
985+
top: 'top',
987986
} as const;
988987

989988
// $FlowFixMe[unclear-type] Unclear type. Using `any` type is not safe.

packages/react-native/Libraries/Utilities/Appearance.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let lazyState: ?{
3535
/**
3636
* Ensures that all state and listeners are lazily initialized correctly.
3737
*/
38-
function getState(): $NonMaybeType<typeof lazyState> {
38+
function getState(): NonNullable<typeof lazyState> {
3939
if (lazyState != null) {
4040
return lazyState;
4141
}
@@ -50,7 +50,7 @@ function getState(): $NonMaybeType<typeof lazyState> {
5050
eventEmitter,
5151
};
5252
} else {
53-
const state: $NonMaybeType<typeof lazyState> = {
53+
const state: NonNullable<typeof lazyState> = {
5454
NativeAppearance,
5555
appearance: null,
5656
eventEmitter,

packages/react-native/Libraries/promiseRejectionTrackingOptions.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ import typeof {enable} from 'promise/setimmediate/rejection-tracking';
1212

1313
import ExceptionsManager from './Core/ExceptionsManager';
1414

15-
let rejectionTrackingOptions: $NonMaybeType<Parameters<enable>[0]> = {
15+
const rejectionTrackingOptions: NonNullable<Parameters<enable>[0]> = {
1616
allRejections: true,
17+
onHandled: id => {
18+
const warning =
19+
`Promise rejection handled (id: ${id})\n` +
20+
'This means you can ignore any previous messages of the form ' +
21+
`"Uncaught (in promise, id: ${id})"`;
22+
console.warn(warning);
23+
},
1724
onUnhandled: (id, rejection) => {
1825
let message: string;
1926

@@ -46,13 +53,6 @@ let rejectionTrackingOptions: $NonMaybeType<Parameters<enable>[0]> = {
4653
false /* isFatal */,
4754
);
4855
},
49-
onHandled: id => {
50-
const warning =
51-
`Promise rejection handled (id: ${id})\n` +
52-
'This means you can ignore any previous messages of the form ' +
53-
`"Uncaught (in promise, id: ${id})"`;
54-
console.warn(warning);
55-
},
5656
};
5757

5858
export default rejectionTrackingOptions;

0 commit comments

Comments
 (0)