Skip to content

Commit a0ee6fa

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Annotate empty arrays in xplat
Summary: Changelog: [Internal] Differential Revision: D40410427 fbshipit-source-id: f819fcb00673e19b21aecb383541850436805a0e
1 parent cb2dcd3 commit a0ee6fa

File tree

15 files changed

+27
-23
lines changed

15 files changed

+27
-23
lines changed

Libraries/Core/Devtools/parseErrorStack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {HermesParsedStack} from './parseHermesStack';
1616
const parseHermesStack = require('./parseHermesStack');
1717

1818
function convertHermesStack(stack: HermesParsedStack): Array<StackFrame> {
19-
const frames = [];
19+
const frames: Array<StackFrame> = [];
2020
for (const entry of stack.entries) {
2121
if (entry.type !== 'FRAME') {
2222
continue;

Libraries/Lists/FlatList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
571571
const numColumns = numColumnsOrDefault(this.props.numColumns);
572572
if (onViewableItemsChanged) {
573573
if (numColumns > 1) {
574-
const changed = [];
575-
const viewableItems = [];
574+
const changed: Array<ViewToken> = [];
575+
const viewableItems: Array<ViewToken> = [];
576576
info.viewableItems.forEach(v =>
577577
this._pushMultiColumnViewable(viewableItems, v),
578578
);

Libraries/Lists/ViewabilityHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class ViewabilityHelper {
214214
) {
215215
return;
216216
}
217-
let viewableIndices = [];
217+
let viewableIndices: Array<number> = [];
218218
if (itemCount) {
219219
viewableIndices = this.computeViewableItems(
220220
props,

Libraries/Lists/VirtualizedList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ export default class VirtualizedList extends StateSafePureComponent<
811811
? styles.horizontallyInverted
812812
: styles.verticallyInverted
813813
: null;
814-
const cells = [];
814+
const cells: Array<any | React.Node> = [];
815815
const stickyIndicesFromProps = new Set(this.props.stickyHeaderIndices);
816816
const stickyHeaderIndices = [];
817817

Libraries/Lists/VirtualizedSectionList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class VirtualizedSectionList<
173173
const listHeaderOffset = this.props.ListHeaderComponent ? 1 : 0;
174174

175175
const stickyHeaderIndices = this.props.stickySectionHeadersEnabled
176-
? []
176+
? ([]: Array<number>)
177177
: undefined;
178178

179179
let itemCount = 0;

Libraries/LogBox/Data/LogBoxSymbolication.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const sanitize = ({
2727
if (!Array.isArray(maybeStack)) {
2828
throw new Error('Expected stack to be an array.');
2929
}
30-
const stack = [];
30+
const stack: Array<StackFrame> = [];
3131
for (const maybeFrame of maybeStack) {
3232
let collapse = false;
3333
if ('collapse' in maybeFrame) {

Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
'use strict';
1313

14+
import type {StackFrame} from '../../../Core/NativeExceptionsManager';
15+
1416
const {parseLogBoxException, parseLogBoxLog} = require('../parseLogBoxLog');
1517

1618
describe('parseLogBoxLog', () => {
@@ -230,7 +232,7 @@ describe('parseLogBoxLog', () => {
230232
name: '',
231233
isComponentError: false,
232234
componentStack: '',
233-
stack: [],
235+
stack: ([]: Array<StackFrame>),
234236
id: 0,
235237
isFatal: true,
236238
};
@@ -267,7 +269,7 @@ describe('parseLogBoxLog', () => {
267269
name: '',
268270
isComponentError: false,
269271
componentStack: '',
270-
stack: [],
272+
stack: ([]: Array<StackFrame>),
271273
id: 0,
272274
isFatal: true,
273275
};
@@ -327,7 +329,7 @@ If you are sure the module exists, try these steps:
327329
name: '',
328330
isComponentError: false,
329331
componentStack: '',
330-
stack: [],
332+
stack: ([]: Array<StackFrame>),
331333
id: 0,
332334
isFatal: true,
333335
};
@@ -381,7 +383,7 @@ If you are sure the module exists, try these steps:
381383
name: '',
382384
isComponentError: false,
383385
componentStack: '',
384-
stack: [],
386+
stack: ([]: Array<StackFrame>),
385387
id: 0,
386388
isFatal: true,
387389
};
@@ -429,7 +431,7 @@ Please follow the instructions at: fburl.com/rn-remote-assets
429431
name: '',
430432
isComponentError: false,
431433
componentStack: '',
432-
stack: [],
434+
stack: ([]: Array<StackFrame>),
433435
id: 0,
434436
isFatal: true,
435437
};
@@ -475,7 +477,7 @@ Please follow the instructions at: fburl.com/rn-remote-assets
475477
name: '',
476478
isComponentError: false,
477479
componentStack: '',
478-
stack: [],
480+
stack: ([]: Array<StackFrame>),
479481
id: 0,
480482
isFatal: true,
481483
};

Libraries/LogBox/Data/parseLogBoxLog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export function parseLogBoxLog(args: $ReadOnlyArray<mixed>): {|
317317
message: Message,
318318
|} {
319319
const message = args[0];
320-
let argsWithoutComponentStack = [];
320+
let argsWithoutComponentStack: Array<mixed> = [];
321321
let componentStack: ComponentStack = [];
322322

323323
// Extract component stack from warnings like "Some warning%s".

Libraries/NativeComponent/StaticViewConfigValidator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function validate(
4747
nativeViewConfig: ViewConfig,
4848
staticViewConfig: ViewConfig,
4949
): ValidationResult {
50-
const differences = [];
50+
const differences: Array<Difference> = [];
5151
accumulateDifferences(
5252
differences,
5353
[],

Libraries/Utilities/__tests__/useRefEffect-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function mockEffectRegistry(): {
9494
mockEffectWithoutCleanup: string => () => void,
9595
registry: $ReadOnlyArray<TestEffect | TestEffectCleanup>,
9696
} {
97-
const registry = [];
97+
const registry: Array<TestEffect | TestEffectCleanup> = [];
9898
return {
9999
mockEffect(name: string): () => () => void {
100100
return instance => {

Libraries/Utilities/groupByEveryN.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
function groupByEveryN<T>(array: Array<T>, n: number): Array<Array<?T>> {
3030
const result = [];
31-
let temp = [];
31+
let temp: Array<?T> = [];
3232

3333
for (let i = 0; i < array.length; ++i) {
3434
if (i > 0 && i % n === 0) {

Libraries/Utilities/stringifySafe.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export function createStringifySafeWithLimits(limits: {|
2626
maxArrayLimit = Number.POSITIVE_INFINITY,
2727
maxObjectKeysLimit = Number.POSITIVE_INFINITY,
2828
} = limits;
29-
const stack = [];
29+
const stack: Array<
30+
string | {+[string]: mixed} | {'...(truncated keys)...': number},
31+
> = [];
3032
/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
3133
* Flow's LTI update could not be added via codemod */
3234
function replacer(key: string, value: mixed): mixed {

packages/hermes-inspector-msggen/src/Graph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class Graph {
6363
root.children.add(node);
6464
}
6565

66-
const output = [];
66+
const output: Array<NodeId> = [];
6767
postorder(root, output);
6868

6969
// remove fake root node

packages/hermes-inspector-msggen/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ function parseDomains(
4444
includeExperimental: Set<string>,
4545
): Descriptor {
4646
const desc = {
47-
types: [],
48-
commands: [],
49-
events: [],
47+
types: ([]: Array<Type>),
48+
commands: ([]: Array<Command>),
49+
events: ([]: Array<Event>),
5050
};
5151

5252
for (const obj of domainObjs) {

packages/rn-tester/js/examples/XHR/XHRExampleFetch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class XHRExampleFetch extends React.Component<any, any> {
4444
return null;
4545
}
4646

47-
const responseHeaders = [];
47+
const responseHeaders: Array<React.Node> = [];
4848
const keys = Object.keys(this.responseHeaders.map);
4949
for (let i = 0; i < keys.length; i++) {
5050
const key = keys[i];

0 commit comments

Comments
 (0)