Skip to content

Commit

Permalink
Pre-suppress unsafe string key access errors in xplat/js
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#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
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Apr 23, 2024
1 parent 6e772b2 commit 3dc77ce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/metro-resolver/src/PackageResolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -165,6 +166,7 @@ function matchSubpathFromMainFields(
mainFields: $ReadOnlyArray<string>,
): string | false | null {
const fieldValues = mainFields
// $FlowFixMe[invalid-computed-prop]
.map(name => pkg[name])
.filter(value => value != null && typeof value !== 'string');

Expand Down
1 change: 1 addition & 0 deletions packages/metro/src/lib/logToConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = (
mode: 'BRIDGE' | 'NOBRIDGE',
...data: Array<mixed>
) => {
// $FlowFixMe[invalid-computed-prop]
const logFunction = console[level] && level !== 'trace' ? level : 'log';
const color =
level === 'error'
Expand Down

0 comments on commit 3dc77ce

Please sign in to comment.