Skip to content

Commit a8984b7

Browse files
marcoww6meta-codesync[bot]
authored andcommitted
Transform $Keys to keyof (#55111)
Summary: Pull Request resolved: #55111 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 Command: `js1 flow-runner codemod flow/transformUtilityType --format-files=false --legacy-type='$ReadOnlySet'` Reviewed By: SamChou19815 Differential Revision: D90426061
1 parent b45c820 commit a8984b7

File tree

31 files changed

+92
-100
lines changed

31 files changed

+92
-100
lines changed

flow-typed/npm/babel-traverse_v7.x.x.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,24 +558,24 @@ declare module '@babel/traverse' {
558558
* Check whether we have the input `key`. If the `key` references an array then we check
559559
* if the array has any items, otherwise we just check if it's falsy.
560560
*/
561-
has(key: $Keys<TNode>): boolean;
561+
has(key: keyof TNode): boolean;
562562

563563
isStatic(): boolean;
564564

565565
/**
566566
* Alias of `has`.
567567
*/
568-
is(key: $Keys<TNode>): boolean;
568+
is(key: keyof TNode): boolean;
569569

570570
/**
571571
* Opposite of `has`.
572572
*/
573-
isnt(key: $Keys<TNode>): boolean;
573+
isnt(key: keyof TNode): boolean;
574574

575575
/**
576576
* Check whether the path node `key` strict equals `value`.
577577
*/
578-
equals(key: $Keys<TNode>, value: any): boolean;
578+
equals(key: keyof TNode, value: any): boolean;
579579

580580
/**
581581
* Check the type against our stored internal type of the node. This is handy when a node has
@@ -726,7 +726,7 @@ declare module '@babel/traverse' {
726726

727727
getAllPrevSiblings(): Array<NodePath<>>;
728728

729-
get<TKey: $Keys<TNode>>(
729+
get<TKey: keyof TNode>(
730730
key: TKey,
731731
context?: boolean | TraversalContext,
732732
): TNode[TKey] extends BabelNode ? NodePath<> : Array<NodePath<>>;

flow-typed/npm/rxjs_v6.x.x.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,10 +2193,10 @@ declare module 'rxjs/operators' {
21932193
): rxjs$MonoTypeOperatorFunction<T>;
21942194

21952195
declare export function distinctUntilKeyChanged<T>(
2196-
key: $Keys<T>,
2196+
key: keyof T,
21972197
): rxjs$MonoTypeOperatorFunction<T>;
21982198

2199-
declare export function distinctUntilKeyChanged<T, K: $Keys<T>>(
2199+
declare export function distinctUntilKeyChanged<T, K: keyof T>(
22002200
key: K,
22012201
compare: (x: unknown, y: unknown) => boolean,
22022202
): rxjs$MonoTypeOperatorFunction<T>;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ export default class Device {
480480
/**
481481
* Returns `true` if a page supports the given target capability flag.
482482
*/
483-
#pageHasCapability(page: Page, flag: $Keys<TargetCapabilityFlags>): boolean {
483+
#pageHasCapability(page: Page, flag: keyof TargetCapabilityFlags): boolean {
484484
return page.capabilities[flag] === true;
485485
}
486486

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import type {JSONSerializable} from '../types';
1212
import type {Commands, Events} from './protocol';
1313

1414
// Note: A CDP event is a JSON-RPC notification with no `id` member.
15-
export type CDPEvent<TEvent: $Keys<Events> = 'unknown'> = {
15+
export type CDPEvent<TEvent: keyof Events = 'unknown'> = {
1616
method: TEvent,
1717
params: Events[TEvent],
1818
};
1919

20-
export type CDPRequest<TCommand: $Keys<Commands> = 'unknown'> = {
20+
export type CDPRequest<TCommand: keyof Commands = 'unknown'> = {
2121
method: TCommand,
2222
params: Commands[TCommand]['paramsType'],
2323
id: number,
2424
};
2525

26-
export type CDPResponse<TCommand: $Keys<Commands> = 'unknown'> =
26+
export type CDPResponse<TCommand: keyof Commands = 'unknown'> =
2727
| {
2828
result: Commands[TCommand]['resultType'],
2929
id: number,

packages/react-native/Libraries/Animated/createAnimatedComponent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ type PassThroughProps = Readonly<{
6565
passthroughAnimatedPropExplicitValues?: ViewProps | null,
6666
}>;
6767

68-
type LooseOmit<O: interface {}, K: $Keys<$FlowFixMe>> = Pick<
68+
type LooseOmit<O: interface {}, K: keyof $FlowFixMe> = Pick<
6969
O,
70-
Exclude<$Keys<O>, K>,
70+
Exclude<keyof O, K>,
7171
>;
7272

7373
export type AnimatedProps<Props: {...}> = LooseOmit<

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type AppStateEventDefinitions = {
4242
focus: [],
4343
};
4444

45-
export type AppStateEvent = $Keys<AppStateEventDefinitions>;
45+
export type AppStateEvent = keyof AppStateEventDefinitions;
4646

4747
type NativeAppStateEventDefinitions = {
4848
appStateDidChange: [{app_state: AppStateStatus}],

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,28 @@ type AccessibilityEventTypes =
4949
| 'windowStateChange';
5050

5151
// Mapping of public event names to platform-specific event names.
52-
const EventNames: Map<
53-
$Keys<AccessibilityEventDefinitions>,
54-
string,
55-
> = Platform.OS === 'android'
56-
? new Map([
57-
['change', 'touchExplorationDidChange'],
58-
['reduceMotionChanged', 'reduceMotionDidChange'],
59-
['highTextContrastChanged', 'highTextContrastDidChange'],
60-
['screenReaderChanged', 'touchExplorationDidChange'],
61-
['accessibilityServiceChanged', 'accessibilityServiceDidChange'],
62-
['invertColorsChanged', 'invertColorDidChange'],
63-
['grayscaleChanged', 'grayscaleModeDidChange'],
64-
])
65-
: new Map([
66-
['announcementFinished', 'announcementFinished'],
67-
['boldTextChanged', 'boldTextChanged'],
68-
['change', 'screenReaderChanged'],
69-
['grayscaleChanged', 'grayscaleChanged'],
70-
['invertColorsChanged', 'invertColorsChanged'],
71-
['reduceMotionChanged', 'reduceMotionChanged'],
72-
['reduceTransparencyChanged', 'reduceTransparencyChanged'],
73-
['screenReaderChanged', 'screenReaderChanged'],
74-
['darkerSystemColorsChanged', 'darkerSystemColorsChanged'],
75-
]);
52+
const EventNames: Map<keyof AccessibilityEventDefinitions, string> =
53+
Platform.OS === 'android'
54+
? new Map([
55+
['change', 'touchExplorationDidChange'],
56+
['reduceMotionChanged', 'reduceMotionDidChange'],
57+
['highTextContrastChanged', 'highTextContrastDidChange'],
58+
['screenReaderChanged', 'touchExplorationDidChange'],
59+
['accessibilityServiceChanged', 'accessibilityServiceDidChange'],
60+
['invertColorsChanged', 'invertColorDidChange'],
61+
['grayscaleChanged', 'grayscaleModeDidChange'],
62+
])
63+
: new Map([
64+
['announcementFinished', 'announcementFinished'],
65+
['boldTextChanged', 'boldTextChanged'],
66+
['change', 'screenReaderChanged'],
67+
['grayscaleChanged', 'grayscaleChanged'],
68+
['invertColorsChanged', 'invertColorsChanged'],
69+
['reduceMotionChanged', 'reduceMotionChanged'],
70+
['reduceTransparencyChanged', 'reduceTransparencyChanged'],
71+
['screenReaderChanged', 'screenReaderChanged'],
72+
['darkerSystemColorsChanged', 'darkerSystemColorsChanged'],
73+
]);
7674

7775
/**
7876
* Sometimes it's useful to know whether or not the device has a screen reader
@@ -426,7 +424,7 @@ const AccessibilityInfo = {
426424
*
427425
* See https://reactnative.dev/docs/accessibilityinfo#addeventlistener
428426
*/
429-
addEventListener<K: $Keys<AccessibilityEventDefinitions>>(
427+
addEventListener<K: keyof AccessibilityEventDefinitions>(
430428
eventName: K,
431429
// $FlowFixMe[incompatible-type] - Flow bug with unions and generics (T128099423)
432430
handler: (...AccessibilityEventDefinitions[K]) => void,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import dismissKeyboard from '../../Utilities/dismissKeyboard';
1616
import Platform from '../../Utilities/Platform';
1717
import NativeKeyboardObserver from './NativeKeyboardObserver';
1818

19-
export type KeyboardEventName = $Keys<KeyboardEventDefinitions>;
19+
export type KeyboardEventName = keyof KeyboardEventDefinitions;
2020

2121
export type KeyboardEventEasing =
2222
| 'easeIn'
@@ -146,7 +146,7 @@ class KeyboardImpl {
146146
*
147147
* @param {function} callback function to be called when the event fires.
148148
*/
149-
addListener<K: $Keys<KeyboardEventDefinitions>>(
149+
addListener<K: keyof KeyboardEventDefinitions>(
150150
eventType: K,
151151
listener: (...KeyboardEventDefinitions[K]) => unknown,
152152
context?: unknown,
@@ -159,7 +159,7 @@ class KeyboardImpl {
159159
*
160160
* @param {string} eventType The native event string listeners are watching which will be removed.
161161
*/
162-
removeAllListeners<K: $Keys<KeyboardEventDefinitions>>(eventType: ?K): void {
162+
removeAllListeners<K: keyof KeyboardEventDefinitions>(eventType: ?K): void {
163163
this._emitter.removeAllListeners(eventType);
164164
}
165165

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type {ProgressBarAndroidProps};
2121
// of ProgressBarAndroidProps. TS's Omit does not distribute over unions, so
2222
// we define our own version which does. This does not affect Flow.
2323
// $FlowExpectedError[unclear-type]
24-
type Omit<T, K> = T extends any ? Pick<T, Exclude<$Keys<T>, K>> : T;
24+
type Omit<T, K> = T extends any ? Pick<T, Exclude<keyof T, K>> : T;
2525

2626
/**
2727
* ProgressBarAndroid has been extracted from react-native core and will be removed in a future release.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as React from 'react';
2020
/**
2121
* Status bar style
2222
*/
23-
export type StatusBarStyle = $Keys<{
23+
export type StatusBarStyle = keyof {
2424
/**
2525
* Default status bar style (dark for iOS, light for Android)
2626
*/
@@ -34,12 +34,12 @@ export type StatusBarStyle = $Keys<{
3434
*/
3535
'dark-content': string,
3636
...
37-
}>;
37+
};
3838

3939
/**
4040
* Status bar animation
4141
*/
42-
export type StatusBarAnimation = $Keys<{
42+
export type StatusBarAnimation = keyof {
4343
/**
4444
* No animation
4545
*/
@@ -53,7 +53,7 @@ export type StatusBarAnimation = $Keys<{
5353
*/
5454
slide: string,
5555
...
56-
}>;
56+
};
5757

5858
export type StatusBarPropsAndroid = Readonly<{
5959
/**

0 commit comments

Comments
 (0)