Skip to content

Commit 6b85c54

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Add annotations to array and object literal declarations to fix future natural inference errors (#52267)
Summary: Pull Request resolved: #52267 Changelog: [Internal] Reviewed By: marcoww6 Differential Revision: D77308192 fbshipit-source-id: 21fa2f6d3df632941327b9b2d7910b035f16b7d2
1 parent 7e8eadc commit 6b85c54

6 files changed

Lines changed: 27 additions & 22 deletions

File tree

packages/dev-middleware/src/__tests__/StandaloneFuseboxShell-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import type {JsonPagesListResponse} from '../inspector-proxy/types';
12+
import type {BrowserLauncher} from '../types/BrowserLauncher';
1213

1314
import DefaultBrowserLauncher from '../utils/DefaultBrowserLauncher';
1415
import {fetchJson, requestLocal} from './FetchUtils';
@@ -22,7 +23,7 @@ const PAGES_POLLING_DELAY = 2100;
2223
jest.useFakeTimers();
2324

2425
describe('enableStandaloneFuseboxShell experiment', () => {
25-
const BrowserLauncherWithFuseboxShell = {
26+
const BrowserLauncherWithFuseboxShell: BrowserLauncher = {
2627
...DefaultBrowserLauncher,
2728
unstable_showFuseboxShell: () => {
2829
throw new Error('Not implemented');

packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010

1111
'use strict';
12-
1312
import type {StackFrame} from '../../../Core/NativeExceptionsManager';
13+
import type {ExtendedExceptionData} from '../parseLogBoxLog';
1414

1515
const {
1616
parseLogBoxException,
@@ -296,7 +296,7 @@ describe('parseLogBoxLog', () => {
296296
});
297297

298298
it('parses a babel transform syntax error', () => {
299-
const error = {
299+
const error: ExtendedExceptionData = {
300300
message: `
301301
302302
197 | });
@@ -344,7 +344,7 @@ describe('parseLogBoxLog', () => {
344344
});
345345

346346
it('parses an invalid require syntax error', () => {
347-
const error = {
347+
const error: ExtendedExceptionData = {
348348
message: `Unable to resolve module \`ListCellx\` from /path/to/file.js: ListCellx could not be found within the project.
349349
350350
If you are sure the module exists, try these steps:
@@ -414,7 +414,7 @@ If you are sure the module exists, try these steps:
414414
});
415415

416416
it('parses a reference error', () => {
417-
const error = {
417+
const error: ExtendedExceptionData = {
418418
message: `
419419
420420
197 | });
@@ -462,7 +462,7 @@ If you are sure the module exists, try these steps:
462462
});
463463

464464
it('parses a babel codeframe error', () => {
465-
const error = {
465+
const error: ExtendedExceptionData = {
466466
message: `TransformError RKJSModules/Apps/CrashReact/CrashReactApp.js: /path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js: The first argument to \`fbRemoteAsset\` is "null_state_glyphs", but the requested asset is missing from the local metadata. Either the asset does not exist or the metadata is not up-to-date.
467467
468468
Please follow the instructions at: fburl.com/rn-remote-assets
@@ -514,7 +514,7 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
514514
});
515515

516516
it('parses a babel codeframe error with ansi', () => {
517-
const error = {
517+
const error: ExtendedExceptionData = {
518518
message: `TransformError RKJSModules/Apps/CrashReact/CrashReactApp.js: /path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js: The first argument to \`fbRemoteAsset\` is "null_state_glyphs", but the requested asset is missing from the local metadata. Either the asset does not exist or the metadata is not up-to-date.
519519
520520
Please follow the instructions at: fburl.com/rn-remote-assets

packages/react-native/Libraries/StyleSheet/__tests__/processBackgroundImage-test.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @format
99
*/
1010

11+
import type {BackgroundImageValue} from '../StyleSheetTypes';
12+
1113
import processBackgroundImage from '../processBackgroundImage';
1214

1315
const {OS} = require('../../Utilities/Platform').default;
@@ -121,7 +123,7 @@ describe('processBackgroundImage', () => {
121123
});
122124

123125
it('should process a linear gradient object style with case-insensitive direction keyword', () => {
124-
const input = [
126+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
125127
{
126128
type: 'linear-gradient' as const,
127129
direction: 'To Bottom',
@@ -138,7 +140,7 @@ describe('processBackgroundImage', () => {
138140
});
139141

140142
it('should process a linear gradient object style with case-insensitive angle', () => {
141-
const input = [
143+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
142144
{
143145
type: 'linear-gradient' as const,
144146
direction: '45DEG',
@@ -350,7 +352,7 @@ describe('processBackgroundImage', () => {
350352
});
351353

352354
it('should process an array of style objects', () => {
353-
const input = [
355+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
354356
{
355357
type: 'linear-gradient' as const,
356358
direction: 'to bottom right',
@@ -374,7 +376,7 @@ describe('processBackgroundImage', () => {
374376
});
375377

376378
it('should process an style object with default direction', () => {
377-
const input = [
379+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
378380
{
379381
type: 'linear-gradient' as const,
380382
colorStops: [{color: 'red'}, {color: 'blue'}],
@@ -388,7 +390,7 @@ describe('processBackgroundImage', () => {
388390
});
389391

390392
it('should process style object with direction enum', () => {
391-
const input = [
393+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
392394
{
393395
type: 'linear-gradient' as const,
394396
direction: 'to right',
@@ -403,7 +405,7 @@ describe('processBackgroundImage', () => {
403405
});
404406

405407
it('should process style object with direction angle', () => {
406-
const input = [
408+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
407409
{
408410
type: 'linear-gradient' as const,
409411
direction: '45deg',
@@ -418,7 +420,7 @@ describe('processBackgroundImage', () => {
418420
});
419421

420422
it('should fix up stop positions #1', () => {
421-
const input = [
423+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
422424
{
423425
type: 'linear-gradient' as const,
424426
colorStops: [
@@ -456,7 +458,7 @@ describe('processBackgroundImage', () => {
456458
});
457459

458460
it('should process multiple stop positions', () => {
459-
const input = [
461+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
460462
{
461463
type: 'linear-gradient' as const,
462464
colorStops: [
@@ -493,7 +495,7 @@ describe('processBackgroundImage', () => {
493495
});
494496

495497
it('should fix up stop positions #2', () => {
496-
const input = [
498+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
497499
{
498500
type: 'linear-gradient' as const,
499501
colorStops: [
@@ -526,7 +528,7 @@ describe('processBackgroundImage', () => {
526528
});
527529

528530
it('should fix up stop positions #3', () => {
529-
const input = [
531+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
530532
{
531533
type: 'linear-gradient' as const,
532534
colorStops: [
@@ -559,7 +561,7 @@ describe('processBackgroundImage', () => {
559561
});
560562

561563
it('should fix up stop positions #4', () => {
562-
const input = [
564+
const input: $ReadOnlyArray<BackgroundImageValue> | string = [
563565
{
564566
type: 'linear-gradient' as const,
565567
colorStops: [

packages/rn-tester/js/examples/Experimental/W3CPointerEventPlatformTests/PointerEventPointerMoveAcross.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const relevantEvents = [
6565
'pointerLeave',
6666
];
6767

68-
const expected = [
68+
const expected: Array<{optional?: boolean, target: string, type: string}> = [
6969
{type: 'pointerOver', target: 'a'},
7070
{type: 'pointerEnter', target: 'c'},
7171
{type: 'pointerEnter', target: 'b'},

packages/rn-tester/js/examples/Experimental/W3CPointerEventPlatformTests/PointerEventPointerMoveBetween.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const relevantEvents = [
4747
'pointerLeave',
4848
];
4949

50-
const expected = [
50+
const expected: Array<{optional?: boolean, target: string, type: string}> = [
5151
{type: 'pointerOver', target: 'a'},
5252
{type: 'pointerEnter', target: 'a'},
5353
{type: 'pointerMove', target: 'a', optional: true},

packages/virtualized-lists/Lists/__tests__/ViewabilityHelper-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
* @format
99
*/
1010

11+
import type {CellMetricProps} from '../ListMetricsAggregator';
12+
1113
import ViewabilityHelper from '../ViewabilityHelper';
1214

1315
let rowFrames: ?{
1416
[string]: $ReadOnly<{height: number, y: number}>,
1517
};
1618
let data;
17-
const props = {
19+
const props: CellMetricProps = {
1820
data,
1921
getItem: () => {
2022
throw new Error('Unexpected call to `getItem`.');
@@ -486,7 +488,7 @@ describe('onUpdate', function () {
486488
// This test assures we round down the calculations of the item cell layout
487489
// to avoid cases of imprecison when measuring layout
488490
const helper = new ViewabilityHelper({itemVisiblePercentThreshold: 100});
489-
const testProps = {
491+
const testProps: CellMetricProps = {
490492
getItem: () => {
491493
throw new Error('Unexpected call to `getItem`.');
492494
},

0 commit comments

Comments
 (0)