Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions flow-typed/npm/babel-traverse_v7.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,24 +558,24 @@ declare module '@babel/traverse' {
* Check whether we have the input `key`. If the `key` references an array then we check
* if the array has any items, otherwise we just check if it's falsy.
*/
has(key: $Keys<TNode>): boolean;
has(key: keyof TNode): boolean;

isStatic(): boolean;

/**
* Alias of `has`.
*/
is(key: $Keys<TNode>): boolean;
is(key: keyof TNode): boolean;

/**
* Opposite of `has`.
*/
isnt(key: $Keys<TNode>): boolean;
isnt(key: keyof TNode): boolean;

/**
* Check whether the path node `key` strict equals `value`.
*/
equals(key: $Keys<TNode>, value: any): boolean;
equals(key: keyof TNode, value: any): boolean;

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

getAllPrevSiblings(): Array<NodePath<>>;

get<TKey: $Keys<TNode>>(
get<TKey: keyof TNode>(
key: TKey,
context?: boolean | TraversalContext,
): TNode[TKey] extends BabelNode ? NodePath<> : Array<NodePath<>>;
Expand Down
4 changes: 2 additions & 2 deletions flow-typed/npm/rxjs_v6.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -2193,10 +2193,10 @@ declare module 'rxjs/operators' {
): rxjs$MonoTypeOperatorFunction<T>;

declare export function distinctUntilKeyChanged<T>(
key: $Keys<T>,
key: keyof T,
): rxjs$MonoTypeOperatorFunction<T>;

declare export function distinctUntilKeyChanged<T, K: $Keys<T>>(
declare export function distinctUntilKeyChanged<T, K: keyof T>(
key: K,
compare: (x: unknown, y: unknown) => boolean,
): rxjs$MonoTypeOperatorFunction<T>;
Expand Down
4 changes: 2 additions & 2 deletions packages/dev-middleware/src/inspector-proxy/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class Device {
#deviceSocket: WS;

// Stores the most recent listing of device's pages, keyed by the `id` field.
#pages: $ReadOnlyMap<string, Page> = new Map();
#pages: ReadonlyMap<string, Page> = new Map();

// Stores information about currently connected debugger (if any).
#debuggerConnection: ?DebuggerConnection = null;
Expand Down Expand Up @@ -480,7 +480,7 @@ export default class Device {
/**
* Returns `true` if a page supports the given target capability flag.
*/
#pageHasCapability(page: Page, flag: $Keys<TargetCapabilityFlags>): boolean {
#pageHasCapability(page: Page, flag: keyof TargetCapabilityFlags): boolean {
return page.capabilities[flag] === true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import type {JSONSerializable} from '../types';
import type {Commands, Events} from './protocol';

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

export type CDPRequest<TCommand: $Keys<Commands> = 'unknown'> = {
export type CDPRequest<TCommand: keyof Commands = 'unknown'> = {
method: TCommand,
params: Commands[TCommand]['paramsType'],
id: number,
};

export type CDPResponse<TCommand: $Keys<Commands> = 'unknown'> =
export type CDPResponse<TCommand: keyof Commands = 'unknown'> =
| {
result: Commands[TCommand]['resultType'],
id: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ type PassThroughProps = Readonly<{
passthroughAnimatedPropExplicitValues?: ViewProps | null,
}>;

type LooseOmit<O: interface {}, K: $Keys<$FlowFixMe>> = Pick<
type LooseOmit<O: interface {}, K: keyof $FlowFixMe> = Pick<
O,
Exclude<$Keys<O>, K>,
Exclude<keyof O, K>,
>;

export type AnimatedProps<Props: {...}> = LooseOmit<
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/AppState/AppState.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type AppStateEventDefinitions = {
focus: [],
};

export type AppStateEvent = $Keys<AppStateEventDefinitions>;
export type AppStateEvent = keyof AppStateEventDefinitions;

type NativeAppStateEventDefinitions = {
appStateDidChange: [{app_state: AppStateStatus}],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,28 @@ type AccessibilityEventTypes =
| 'windowStateChange';

// Mapping of public event names to platform-specific event names.
const EventNames: Map<
$Keys<AccessibilityEventDefinitions>,
string,
> = Platform.OS === 'android'
? new Map([
['change', 'touchExplorationDidChange'],
['reduceMotionChanged', 'reduceMotionDidChange'],
['highTextContrastChanged', 'highTextContrastDidChange'],
['screenReaderChanged', 'touchExplorationDidChange'],
['accessibilityServiceChanged', 'accessibilityServiceDidChange'],
['invertColorsChanged', 'invertColorDidChange'],
['grayscaleChanged', 'grayscaleModeDidChange'],
])
: new Map([
['announcementFinished', 'announcementFinished'],
['boldTextChanged', 'boldTextChanged'],
['change', 'screenReaderChanged'],
['grayscaleChanged', 'grayscaleChanged'],
['invertColorsChanged', 'invertColorsChanged'],
['reduceMotionChanged', 'reduceMotionChanged'],
['reduceTransparencyChanged', 'reduceTransparencyChanged'],
['screenReaderChanged', 'screenReaderChanged'],
['darkerSystemColorsChanged', 'darkerSystemColorsChanged'],
]);
const EventNames: Map<keyof AccessibilityEventDefinitions, string> =
Platform.OS === 'android'
? new Map([
['change', 'touchExplorationDidChange'],
['reduceMotionChanged', 'reduceMotionDidChange'],
['highTextContrastChanged', 'highTextContrastDidChange'],
['screenReaderChanged', 'touchExplorationDidChange'],
['accessibilityServiceChanged', 'accessibilityServiceDidChange'],
['invertColorsChanged', 'invertColorDidChange'],
['grayscaleChanged', 'grayscaleModeDidChange'],
])
: new Map([
['announcementFinished', 'announcementFinished'],
['boldTextChanged', 'boldTextChanged'],
['change', 'screenReaderChanged'],
['grayscaleChanged', 'grayscaleChanged'],
['invertColorsChanged', 'invertColorsChanged'],
['reduceMotionChanged', 'reduceMotionChanged'],
['reduceTransparencyChanged', 'reduceTransparencyChanged'],
['screenReaderChanged', 'screenReaderChanged'],
['darkerSystemColorsChanged', 'darkerSystemColorsChanged'],
]);

/**
* Sometimes it's useful to know whether or not the device has a screen reader
Expand Down Expand Up @@ -426,7 +424,7 @@ const AccessibilityInfo = {
*
* See https://reactnative.dev/docs/accessibilityinfo#addeventlistener
*/
addEventListener<K: $Keys<AccessibilityEventDefinitions>>(
addEventListener<K: keyof AccessibilityEventDefinitions>(
eventName: K,
// $FlowFixMe[incompatible-type] - Flow bug with unions and generics (T128099423)
handler: (...AccessibilityEventDefinitions[K]) => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import dismissKeyboard from '../../Utilities/dismissKeyboard';
import Platform from '../../Utilities/Platform';
import NativeKeyboardObserver from './NativeKeyboardObserver';

export type KeyboardEventName = $Keys<KeyboardEventDefinitions>;
export type KeyboardEventName = keyof KeyboardEventDefinitions;

export type KeyboardEventEasing =
| 'easeIn'
Expand Down Expand Up @@ -146,7 +146,7 @@ class KeyboardImpl {
*
* @param {function} callback function to be called when the event fires.
*/
addListener<K: $Keys<KeyboardEventDefinitions>>(
addListener<K: keyof KeyboardEventDefinitions>(
eventType: K,
listener: (...KeyboardEventDefinitions[K]) => unknown,
context?: unknown,
Expand All @@ -159,7 +159,7 @@ class KeyboardImpl {
*
* @param {string} eventType The native event string listeners are watching which will be removed.
*/
removeAllListeners<K: $Keys<KeyboardEventDefinitions>>(eventType: ?K): void {
removeAllListeners<K: keyof KeyboardEventDefinitions>(eventType: ?K): void {
this._emitter.removeAllListeners(eventType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type {ProgressBarAndroidProps};
// of ProgressBarAndroidProps. TS's Omit does not distribute over unions, so
// we define our own version which does. This does not affect Flow.
// $FlowExpectedError[unclear-type]
type Omit<T, K> = T extends any ? Pick<T, Exclude<$Keys<T>, K>> : T;
type Omit<T, K> = T extends any ? Pick<T, Exclude<keyof T, K>> : T;

/**
* ProgressBarAndroid has been extracted from react-native core and will be removed in a future release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as React from 'react';
/**
* Status bar style
*/
export type StatusBarStyle = $Keys<{
export type StatusBarStyle = keyof {
/**
* Default status bar style (dark for iOS, light for Android)
*/
Expand All @@ -34,12 +34,12 @@ export type StatusBarStyle = $Keys<{
*/
'dark-content': string,
...
}>;
};

/**
* Status bar animation
*/
export type StatusBarAnimation = $Keys<{
export type StatusBarAnimation = keyof {
/**
* No animation
*/
Expand All @@ -53,7 +53,7 @@ export type StatusBarAnimation = $Keys<{
*/
slide: string,
...
}>;
};

export type StatusBarPropsAndroid = Readonly<{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class NativeEventEmitter<
}
}

addListener<TEvent: $Keys<TEventToArgsMap>>(
addListener<TEvent: keyof TEventToArgsMap>(
eventType: TEvent,
listener: (...args: TEventToArgsMap[TEvent]) => unknown,
context?: unknown,
Expand All @@ -107,7 +107,7 @@ export default class NativeEventEmitter<
};
}

emit<TEvent: $Keys<TEventToArgsMap>>(
emit<TEvent: keyof TEventToArgsMap>(
eventType: TEvent,
...args: TEventToArgsMap[TEvent]
): void {
Expand All @@ -116,9 +116,7 @@ export default class NativeEventEmitter<
RCTDeviceEventEmitter.emit(eventType, ...args);
}

removeAllListeners<TEvent: $Keys<TEventToArgsMap>>(
eventType?: ?TEvent,
): void {
removeAllListeners<TEvent: keyof TEventToArgsMap>(eventType?: ?TEvent): void {
invariant(
eventType != null,
'`NativeEventEmitter.removeAllListener()` requires a non-null argument.',
Expand All @@ -127,7 +125,7 @@ export default class NativeEventEmitter<
RCTDeviceEventEmitter.removeAllListeners(eventType);
}

listenerCount<TEvent: $Keys<TEventToArgsMap>>(eventType: TEvent): number {
listenerCount<TEvent: keyof TEventToArgsMap>(eventType: TEvent): number {
return RCTDeviceEventEmitter.listenerCount(eventType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type RCTDeviceEventDefinitions = {[name: string]: Array<any>};
*/
class RCTDeviceEventEmitterImpl extends EventEmitter<RCTDeviceEventDefinitions> {
// Add systrace to RCTDeviceEventEmitter.emit method for debugging
emit<TEvent: $Keys<RCTDeviceEventDefinitions>>(
emit<TEvent: keyof RCTDeviceEventDefinitions>(
eventType: TEvent,
...args: RCTDeviceEventDefinitions[TEvent]
): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,26 @@ export default class NativeEventEmitter<
TEventToArgsMap: Readonly<Record<string, $ReadOnlyArray<unknown>>>,
> implements IEventEmitter<TEventToArgsMap>
{
addListener<TEvent: $Keys<TEventToArgsMap>>(
addListener<TEvent: keyof TEventToArgsMap>(
eventType: TEvent,
listener: (...args: TEventToArgsMap[TEvent]) => unknown,
context?: unknown,
): EventSubscription {
return RCTDeviceEventEmitter.addListener(eventType, listener, context);
}

emit<TEvent: $Keys<TEventToArgsMap>>(
emit<TEvent: keyof TEventToArgsMap>(
eventType: TEvent,
...args: TEventToArgsMap[TEvent]
): void {
RCTDeviceEventEmitter.emit(eventType, ...args);
}

removeAllListeners<TEvent: $Keys<TEventToArgsMap>>(
eventType?: ?TEvent,
): void {
removeAllListeners<TEvent: keyof TEventToArgsMap>(eventType?: ?TEvent): void {
RCTDeviceEventEmitter.removeAllListeners(eventType);
}

listenerCount<TEvent: $Keys<TEventToArgsMap>>(eventType: TEvent): number {
listenerCount<TEvent: keyof TEventToArgsMap>(eventType: TEvent): number {
return RCTDeviceEventEmitter.listenerCount(eventType);
}
}
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Linking/Linking.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LinkingImpl extends NativeEventEmitter<LinkingEventDefinitions> {
*
* See https://reactnative.dev/docs/linking#addeventlistener
*/
addEventListener<K: $Keys<LinkingEventDefinitions>>(
addEventListener<K: keyof LinkingEventDefinitions>(
eventType: K,
listener: (...LinkingEventDefinitions[K]) => unknown,
): EventSubscription {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const emitter = new NativeEventEmitter<$FlowFixMe>(
* requestId to each network request that can be used to abort that request later on.
*/
const RCTNetworking = {
addListener<K: $Keys<RCTNetworkingEventDefinitions>>(
addListener<K: keyof RCTNetworkingEventDefinitions>(
eventType: K,
listener: (...RCTNetworkingEventDefinitions[K]) => unknown,
context?: unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {type RCTNetworkingEventDefinitions} from './RCTNetworkingEventDefinition
import {type NativeResponseType} from './XMLHttpRequest';

const RCTNetworking = {
addListener<K: $Keys<RCTNetworkingEventDefinitions>>(
addListener<K: keyof RCTNetworkingEventDefinitions>(
eventType: K,
listener: (...RCTNetworkingEventDefinitions[K]) => unknown,
context?: unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {RCTNetworkingEventDefinitions} from './RCTNetworkingEventDefinition
import type {NativeResponseType} from './XMLHttpRequest';

declare const RCTNetworking: interface {
addListener<K: $Keys<RCTNetworkingEventDefinitions>>(
addListener<K: keyof RCTNetworkingEventDefinitions>(
eventType: K,
// $FlowFixMe[invalid-computed-prop]
listener: (...RCTNetworkingEventDefinitions[K]) => unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export type FetchResult = {
/**
* An event emitted by PushNotificationIOS.
*/
export type PushNotificationEventName = $Keys<{
export type PushNotificationEventName = keyof {
/**
* Fired when a remote notification is received. The handler will be invoked
* with an instance of `PushNotificationIOS`. This will handle notifications
Expand All @@ -116,7 +116,7 @@ export type PushNotificationEventName = $Keys<{
*/
registrationError: string,
...
}>;
};

export interface PushNotification {
/**
Expand Down
Loading
Loading