Skip to content

Commit d5d146d

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Replace literal dictionary keys with properties or Record
Summary: Replaces Flow object indexers whose key types are literal unions (for example `{[key: 'a' | 'b']: V}`) with explicit properties or `Record` / `Partial<Record>` across React Native and Metro packages. Dictionary indexers do not require literal union keys to be present and treat finite key sets as dynamic dictionaries; explicit properties and `Record` express these finite object shapes directly with no runtime changes. Changelog: [Internal] Differential Revision: D136526662
1 parent 01ec383 commit d5d146d

9 files changed

Lines changed: 28 additions & 24 deletions

File tree

‎flow-typed/npm/shelljs_v0.x.x.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ declare interface $npm$shelljs$Env {
2828
}
2929

3030
declare type $npm$shelljs$OptionsPoly<Flags extends string> = {
31-
[keys: Flags]: boolean,
31+
...Partial<Record<Flags, boolean>>,
3232
...
3333
};
3434
declare interface $npm$shelljs$ExecThen {
@@ -50,7 +50,9 @@ declare type $npm$shelljs$SortOpts = $npm$shelljs$OptionsPoly<'-n' | '-r'>;
5050
declare type $npm$shelljs$TestOpts =
5151
'-b' | '-c' | '-d' | '-e' | '-f' | '-L' | '-p' | '-S';
5252
declare type $npm$shelljs$TouchOpts = {
53-
[key: '-a' | '-c' | '-m']: boolean,
53+
'-a'?: boolean,
54+
'-c'?: boolean,
55+
'-m'?: boolean,
5456
'-d'?: string,
5557
'-r'?: string,
5658
...

‎packages/dev-middleware/src/inspector-proxy/CdpDebugLogging.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ function getCDPLogPrefix(destination: CDPMessageDestination): string {
3838
}
3939

4040
export default class CdpDebugLogging {
41-
#cdpMessagesLoggingBatchingFn: {
42-
[key: CDPMessageDestination]: (message: string) => void,
43-
} = {
41+
#cdpMessagesLoggingBatchingFn: Record<
42+
CDPMessageDestination,
43+
(message: string) => void,
44+
> = {
4445
DebuggerToProxy: () => {},
4546
ProxyToDebugger: () => {},
4647
DeviceToProxy: () => {},
@@ -54,9 +55,10 @@ export default class CdpDebugLogging {
5455
}
5556

5657
#initializeThrottledCDPMessageLogging(): void {
57-
const batchingCounters: {
58-
[key: CDPMessageDestination]: {count: number, size: number},
59-
} = {
58+
const batchingCounters: Record<
59+
CDPMessageDestination,
60+
{count: number, size: number},
61+
> = {
6062
DebuggerToProxy: {count: 0, size: 0},
6163
ProxyToDebugger: {count: 0, size: 0},
6264
DeviceToProxy: {count: 0, size: 0},

‎packages/react-native-codegen/src/generators/ReservedPrimitiveTypes.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ type ReservedTypeMapping = {
4343
readonly java: JavaImportInfo,
4444
};
4545

46-
const RESERVED_TYPES: {
47-
readonly [key: ReservedPrimitiveName]: ReservedTypeMapping,
48-
} = {
46+
const RESERVED_TYPES: Readonly<
47+
Record<ReservedPrimitiveName, ReservedTypeMapping>,
48+
> = {
4949
ColorPrimitive: {
5050
cpp: {
5151
typeName: 'SharedColor',

‎packages/react-native/scripts/ios-prebuild/cli.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const platforms /*: ReadonlyArray<Platform> */ = [
2222

2323
// CI can't use commas in cache keys, so 'macOS,variant=Mac Catalyst' was creating troubles
2424
// This map that converts from platforms to valid Xcodebuild destinations.
25-
const platformToDestination /*: Readonly<{[key: Platform]: Destination}> */ = {
25+
const platformToDestination /*: Readonly<Record<Platform, Destination>> */ = {
2626
ios: 'iOS',
2727
'ios-simulator': 'iOS Simulator',
2828
'mac-catalyst': 'macOS,variant=Mac Catalyst',

‎packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestResultView.js‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040

4141
type ViewStyleProp = NonNullable<React.PropOf<View, 'style'>>;
4242

43-
const DISPLAY_STATUS_MAPPING: {[key: PlatformTestResultStatus]: string} = {
43+
const DISPLAY_STATUS_MAPPING: Record<PlatformTestResultStatus, string> = {
4444
PASS: 'Pass',
4545
FAIL: 'Fail',
4646
ERROR: 'Error',
@@ -497,10 +497,9 @@ const styles = StyleSheet.create({
497497
},
498498
});
499499

500-
const STATUS_TEXT_STYLE_MAPPING: {[key: PlatformTestResultStatus]: TextStyle} =
501-
{
502-
PASS: styles.passText,
503-
FAIL: styles.failText,
504-
ERROR: styles.errorText,
505-
SKIPPED: styles.skippedText,
506-
};
500+
const STATUS_TEXT_STYLE_MAPPING: Record<PlatformTestResultStatus, TextStyle> = {
501+
PASS: styles.passText,
502+
FAIL: styles.failText,
503+
ERROR: styles.errorText,
504+
SKIPPED: styles.skippedText,
505+
};

‎packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverScrollMarginPrefetch.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const PREFETCH_DISTANCE = '500px';
3232
const ITEM_COUNT = 50;
3333
const MAX_MESSAGES = 50;
3434

35-
const MODE_EXPLANATIONS: {[mode: MarginMode]: string} = {
35+
const MODE_EXPLANATIONS: Record<MarginMode, string> = {
3636
rootMargin: `rootMargin: '${PREFETCH_DISTANCE} 0px' expands the viewport, but the items are still clipped by the ScrollView, so each one is only reported once it is actually visible. Too late to prefetch.`,
3737
scrollMargin: `scrollMargin: '${PREFETCH_DISTANCE} 0px' expands the clipping area of the ScrollView, so each item is reported ${PREFETCH_DISTANCE} before it scrolls into view.`,
3838
};

‎packages/rn-tester/js/examples/KeyboardAvoidingView/KeyboardAvoidingViewExample.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const BEHAVIORS: Array<KeyboardAvoidingBehavior> = [
6666
'height',
6767
];
6868

69-
const BEHAVIOR_DESCRIPTIONS: {[key: KeyboardAvoidingBehavior]: string} = {
69+
const BEHAVIOR_DESCRIPTIONS: Record<KeyboardAvoidingBehavior, string> = {
7070
padding: 'Sets bottom padding equal to the keyboard overlap.',
7171
position: 'Offsets the content container up by the keyboard overlap.',
7272
height: 'Shrinks the view height by the keyboard overlap.',

‎packages/rn-tester/js/utils/testerStateUtils.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export const initialNavigationState: RNTesterNavigationState = {
3535

3636
const filterEmptySections = (examplesList: ExamplesList): any => {
3737
const filteredSections: {
38-
[key: 'apis' | 'components']: Array<SectionData<RNTesterModuleInfo>>,
38+
apis?: Array<SectionData<RNTesterModuleInfo>>,
39+
components?: Array<SectionData<RNTesterModuleInfo>>,
3940
} = {};
4041
const sectionKeys = Object.keys(examplesList);
4142

‎scripts/releases/ios-prebuild/cli.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {Dependency, Destination, Platform} from './types';
1717

1818
// CI can't use commas in cache keys, so 'macOS,variant=Mac Catalyst' was creating troubles
1919
// This map that converts from platforms to valid Xcodebuild destinations.
20-
const platformToDestination /*: Readonly<{[key: Platform]: Destination}> */ = {
20+
const platformToDestination /*: Readonly<Record<Platform, Destination>> */ = {
2121
ios: 'iOS',
2222
'ios-simulator': 'iOS Simulator',
2323
macos: 'macOS',

0 commit comments

Comments
 (0)