From d5d146d4f326e155cdab674b46cca5a3f8f6b7a6 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Sat, 5 Dec 2026 09:22:19 -0800 Subject: [PATCH] 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` 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 --- flow-typed/npm/shelljs_v0.x.x.js | 6 ++++-- .../src/inspector-proxy/CdpDebugLogging.js | 14 ++++++++------ .../src/generators/ReservedPrimitiveTypes.js | 6 +++--- packages/react-native/scripts/ios-prebuild/cli.js | 2 +- .../RNTesterPlatformTestResultView.js | 15 +++++++-------- .../IntersectionObserverScrollMarginPrefetch.js | 2 +- .../KeyboardAvoidingViewExample.js | 2 +- packages/rn-tester/js/utils/testerStateUtils.js | 3 ++- scripts/releases/ios-prebuild/cli.js | 2 +- 9 files changed, 28 insertions(+), 24 deletions(-) diff --git a/flow-typed/npm/shelljs_v0.x.x.js b/flow-typed/npm/shelljs_v0.x.x.js index 22eb29608ca5..c99f3dc8bf63 100644 --- a/flow-typed/npm/shelljs_v0.x.x.js +++ b/flow-typed/npm/shelljs_v0.x.x.js @@ -28,7 +28,7 @@ declare interface $npm$shelljs$Env { } declare type $npm$shelljs$OptionsPoly = { - [keys: Flags]: boolean, + ...Partial>, ... }; declare interface $npm$shelljs$ExecThen { @@ -50,7 +50,9 @@ declare type $npm$shelljs$SortOpts = $npm$shelljs$OptionsPoly<'-n' | '-r'>; declare type $npm$shelljs$TestOpts = '-b' | '-c' | '-d' | '-e' | '-f' | '-L' | '-p' | '-S'; declare type $npm$shelljs$TouchOpts = { - [key: '-a' | '-c' | '-m']: boolean, + '-a'?: boolean, + '-c'?: boolean, + '-m'?: boolean, '-d'?: string, '-r'?: string, ... diff --git a/packages/dev-middleware/src/inspector-proxy/CdpDebugLogging.js b/packages/dev-middleware/src/inspector-proxy/CdpDebugLogging.js index 1a7200a023c7..dcf83ed62b53 100644 --- a/packages/dev-middleware/src/inspector-proxy/CdpDebugLogging.js +++ b/packages/dev-middleware/src/inspector-proxy/CdpDebugLogging.js @@ -38,9 +38,10 @@ function getCDPLogPrefix(destination: CDPMessageDestination): string { } export default class CdpDebugLogging { - #cdpMessagesLoggingBatchingFn: { - [key: CDPMessageDestination]: (message: string) => void, - } = { + #cdpMessagesLoggingBatchingFn: Record< + CDPMessageDestination, + (message: string) => void, + > = { DebuggerToProxy: () => {}, ProxyToDebugger: () => {}, DeviceToProxy: () => {}, @@ -54,9 +55,10 @@ export default class CdpDebugLogging { } #initializeThrottledCDPMessageLogging(): void { - const batchingCounters: { - [key: CDPMessageDestination]: {count: number, size: number}, - } = { + const batchingCounters: Record< + CDPMessageDestination, + {count: number, size: number}, + > = { DebuggerToProxy: {count: 0, size: 0}, ProxyToDebugger: {count: 0, size: 0}, DeviceToProxy: {count: 0, size: 0}, diff --git a/packages/react-native-codegen/src/generators/ReservedPrimitiveTypes.js b/packages/react-native-codegen/src/generators/ReservedPrimitiveTypes.js index d1f005db7d3f..82d43d6ab12e 100644 --- a/packages/react-native-codegen/src/generators/ReservedPrimitiveTypes.js +++ b/packages/react-native-codegen/src/generators/ReservedPrimitiveTypes.js @@ -43,9 +43,9 @@ type ReservedTypeMapping = { readonly java: JavaImportInfo, }; -const RESERVED_TYPES: { - readonly [key: ReservedPrimitiveName]: ReservedTypeMapping, -} = { +const RESERVED_TYPES: Readonly< + Record, +> = { ColorPrimitive: { cpp: { typeName: 'SharedColor', diff --git a/packages/react-native/scripts/ios-prebuild/cli.js b/packages/react-native/scripts/ios-prebuild/cli.js index 49182ad35da8..6140e407e6f3 100644 --- a/packages/react-native/scripts/ios-prebuild/cli.js +++ b/packages/react-native/scripts/ios-prebuild/cli.js @@ -22,7 +22,7 @@ const platforms /*: ReadonlyArray */ = [ // CI can't use commas in cache keys, so 'macOS,variant=Mac Catalyst' was creating troubles // This map that converts from platforms to valid Xcodebuild destinations. -const platformToDestination /*: Readonly<{[key: Platform]: Destination}> */ = { +const platformToDestination /*: Readonly> */ = { ios: 'iOS', 'ios-simulator': 'iOS Simulator', 'mac-catalyst': 'macOS,variant=Mac Catalyst', diff --git a/packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestResultView.js b/packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestResultView.js index 337563b1d7dd..8f94d21f9832 100644 --- a/packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestResultView.js +++ b/packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestResultView.js @@ -40,7 +40,7 @@ import { type ViewStyleProp = NonNullable>; -const DISPLAY_STATUS_MAPPING: {[key: PlatformTestResultStatus]: string} = { +const DISPLAY_STATUS_MAPPING: Record = { PASS: 'Pass', FAIL: 'Fail', ERROR: 'Error', @@ -497,10 +497,9 @@ const styles = StyleSheet.create({ }, }); -const STATUS_TEXT_STYLE_MAPPING: {[key: PlatformTestResultStatus]: TextStyle} = - { - PASS: styles.passText, - FAIL: styles.failText, - ERROR: styles.errorText, - SKIPPED: styles.skippedText, - }; +const STATUS_TEXT_STYLE_MAPPING: Record = { + PASS: styles.passText, + FAIL: styles.failText, + ERROR: styles.errorText, + SKIPPED: styles.skippedText, +}; diff --git a/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverScrollMarginPrefetch.js b/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverScrollMarginPrefetch.js index 0c2c8e3a6e09..6ee71c4beb7e 100644 --- a/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverScrollMarginPrefetch.js +++ b/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverScrollMarginPrefetch.js @@ -32,7 +32,7 @@ const PREFETCH_DISTANCE = '500px'; const ITEM_COUNT = 50; const MAX_MESSAGES = 50; -const MODE_EXPLANATIONS: {[mode: MarginMode]: string} = { +const MODE_EXPLANATIONS: Record = { 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.`, scrollMargin: `scrollMargin: '${PREFETCH_DISTANCE} 0px' expands the clipping area of the ScrollView, so each item is reported ${PREFETCH_DISTANCE} before it scrolls into view.`, }; diff --git a/packages/rn-tester/js/examples/KeyboardAvoidingView/KeyboardAvoidingViewExample.js b/packages/rn-tester/js/examples/KeyboardAvoidingView/KeyboardAvoidingViewExample.js index c4db571ca9a3..8397c54fbf53 100644 --- a/packages/rn-tester/js/examples/KeyboardAvoidingView/KeyboardAvoidingViewExample.js +++ b/packages/rn-tester/js/examples/KeyboardAvoidingView/KeyboardAvoidingViewExample.js @@ -66,7 +66,7 @@ const BEHAVIORS: Array = [ 'height', ]; -const BEHAVIOR_DESCRIPTIONS: {[key: KeyboardAvoidingBehavior]: string} = { +const BEHAVIOR_DESCRIPTIONS: Record = { padding: 'Sets bottom padding equal to the keyboard overlap.', position: 'Offsets the content container up by the keyboard overlap.', height: 'Shrinks the view height by the keyboard overlap.', diff --git a/packages/rn-tester/js/utils/testerStateUtils.js b/packages/rn-tester/js/utils/testerStateUtils.js index a1939c2d9798..bc3661a16843 100644 --- a/packages/rn-tester/js/utils/testerStateUtils.js +++ b/packages/rn-tester/js/utils/testerStateUtils.js @@ -35,7 +35,8 @@ export const initialNavigationState: RNTesterNavigationState = { const filterEmptySections = (examplesList: ExamplesList): any => { const filteredSections: { - [key: 'apis' | 'components']: Array>, + apis?: Array>, + components?: Array>, } = {}; const sectionKeys = Object.keys(examplesList); diff --git a/scripts/releases/ios-prebuild/cli.js b/scripts/releases/ios-prebuild/cli.js index 5adeef0fdbc5..1d8d5c0fb564 100644 --- a/scripts/releases/ios-prebuild/cli.js +++ b/scripts/releases/ios-prebuild/cli.js @@ -17,7 +17,7 @@ import type {Dependency, Destination, Platform} from './types'; // CI can't use commas in cache keys, so 'macOS,variant=Mac Catalyst' was creating troubles // This map that converts from platforms to valid Xcodebuild destinations. -const platformToDestination /*: Readonly<{[key: Platform]: Destination}> */ = { +const platformToDestination /*: Readonly> */ = { ios: 'iOS', 'ios-simulator': 'iOS Simulator', macos: 'macOS',