From 3dc77ce4afb5cbd05445114027abcf5662658400 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Tue, 23 Apr 2024 11:36:14 -0700 Subject: [PATCH] Pre-suppress unsafe string key access errors in xplat/js Summary: X-link: https://github.com/facebook/react-native/pull/44221 This diff pre-suppresses errors of the following pattern, to prepare for the next Flow release. ``` declare const obj: {foo: string}; declare const key: string; obj[key]; // error: invalid-computed-prop ``` Changelog: [Internal] Reviewed By: alexmckenley Differential Revision: D56477899 fbshipit-source-id: 5676b8685bd3157a519fe433cfce0fa28e003502 --- packages/metro-resolver/src/PackageResolve.js | 2 ++ packages/metro/src/lib/logToConsole.js | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/metro-resolver/src/PackageResolve.js b/packages/metro-resolver/src/PackageResolve.js index f077f44c01..cb2588431f 100644 --- a/packages/metro-resolver/src/PackageResolve.js +++ b/packages/metro-resolver/src/PackageResolve.js @@ -31,6 +31,7 @@ export function getPackageEntryPoint( let main = 'index'; for (const name of mainFields) { + // $FlowFixMe[invalid-computed-prop] if (typeof pkg[name] === 'string' && pkg[name].length) { main = pkg[name]; break; @@ -165,6 +166,7 @@ function matchSubpathFromMainFields( mainFields: $ReadOnlyArray, ): string | false | null { const fieldValues = mainFields + // $FlowFixMe[invalid-computed-prop] .map(name => pkg[name]) .filter(value => value != null && typeof value !== 'string'); diff --git a/packages/metro/src/lib/logToConsole.js b/packages/metro/src/lib/logToConsole.js index bd7a6c34cb..6afdfe00d7 100644 --- a/packages/metro/src/lib/logToConsole.js +++ b/packages/metro/src/lib/logToConsole.js @@ -26,6 +26,7 @@ module.exports = ( mode: 'BRIDGE' | 'NOBRIDGE', ...data: Array ) => { + // $FlowFixMe[invalid-computed-prop] const logFunction = console[level] && level !== 'trace' ? level : 'log'; const color = level === 'error'