Skip to content

Commit

Permalink
Annotate empty arrays in xplat
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal]

Differential Revision: D40410427

fbshipit-source-id: f819fcb00673e19b21aecb383541850436805a0e
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Oct 17, 2022
1 parent cb2dcd3 commit a0ee6fa
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Libraries/Core/Devtools/parseErrorStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {HermesParsedStack} from './parseHermesStack';
const parseHermesStack = require('./parseHermesStack');

function convertHermesStack(stack: HermesParsedStack): Array<StackFrame> {
const frames = [];
const frames: Array<StackFrame> = [];
for (const entry of stack.entries) {
if (entry.type !== 'FRAME') {
continue;
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
const numColumns = numColumnsOrDefault(this.props.numColumns);
if (onViewableItemsChanged) {
if (numColumns > 1) {
const changed = [];
const viewableItems = [];
const changed: Array<ViewToken> = [];
const viewableItems: Array<ViewToken> = [];
info.viewableItems.forEach(v =>
this._pushMultiColumnViewable(viewableItems, v),
);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Lists/ViewabilityHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class ViewabilityHelper {
) {
return;
}
let viewableIndices = [];
let viewableIndices: Array<number> = [];
if (itemCount) {
viewableIndices = this.computeViewableItems(
props,
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ export default class VirtualizedList extends StateSafePureComponent<
? styles.horizontallyInverted
: styles.verticallyInverted
: null;
const cells = [];
const cells: Array<any | React.Node> = [];
const stickyIndicesFromProps = new Set(this.props.stickyHeaderIndices);
const stickyHeaderIndices = [];

Expand Down
2 changes: 1 addition & 1 deletion Libraries/Lists/VirtualizedSectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class VirtualizedSectionList<
const listHeaderOffset = this.props.ListHeaderComponent ? 1 : 0;

const stickyHeaderIndices = this.props.stickySectionHeadersEnabled
? []
? ([]: Array<number>)
: undefined;

let itemCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LogBox/Data/LogBoxSymbolication.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const sanitize = ({
if (!Array.isArray(maybeStack)) {
throw new Error('Expected stack to be an array.');
}
const stack = [];
const stack: Array<StackFrame> = [];
for (const maybeFrame of maybeStack) {
let collapse = false;
if ('collapse' in maybeFrame) {
Expand Down
14 changes: 8 additions & 6 deletions Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

'use strict';

import type {StackFrame} from '../../../Core/NativeExceptionsManager';

const {parseLogBoxException, parseLogBoxLog} = require('../parseLogBoxLog');

describe('parseLogBoxLog', () => {
Expand Down Expand Up @@ -230,7 +232,7 @@ describe('parseLogBoxLog', () => {
name: '',
isComponentError: false,
componentStack: '',
stack: [],
stack: ([]: Array<StackFrame>),
id: 0,
isFatal: true,
};
Expand Down Expand Up @@ -267,7 +269,7 @@ describe('parseLogBoxLog', () => {
name: '',
isComponentError: false,
componentStack: '',
stack: [],
stack: ([]: Array<StackFrame>),
id: 0,
isFatal: true,
};
Expand Down Expand Up @@ -327,7 +329,7 @@ If you are sure the module exists, try these steps:
name: '',
isComponentError: false,
componentStack: '',
stack: [],
stack: ([]: Array<StackFrame>),
id: 0,
isFatal: true,
};
Expand Down Expand Up @@ -381,7 +383,7 @@ If you are sure the module exists, try these steps:
name: '',
isComponentError: false,
componentStack: '',
stack: [],
stack: ([]: Array<StackFrame>),
id: 0,
isFatal: true,
};
Expand Down Expand Up @@ -429,7 +431,7 @@ Please follow the instructions at: fburl.com/rn-remote-assets
name: '',
isComponentError: false,
componentStack: '',
stack: [],
stack: ([]: Array<StackFrame>),
id: 0,
isFatal: true,
};
Expand Down Expand Up @@ -475,7 +477,7 @@ Please follow the instructions at: fburl.com/rn-remote-assets
name: '',
isComponentError: false,
componentStack: '',
stack: [],
stack: ([]: Array<StackFrame>),
id: 0,
isFatal: true,
};
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LogBox/Data/parseLogBoxLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export function parseLogBoxLog(args: $ReadOnlyArray<mixed>): {|
message: Message,
|} {
const message = args[0];
let argsWithoutComponentStack = [];
let argsWithoutComponentStack: Array<mixed> = [];
let componentStack: ComponentStack = [];

// Extract component stack from warnings like "Some warning%s".
Expand Down
2 changes: 1 addition & 1 deletion Libraries/NativeComponent/StaticViewConfigValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function validate(
nativeViewConfig: ViewConfig,
staticViewConfig: ViewConfig,
): ValidationResult {
const differences = [];
const differences: Array<Difference> = [];
accumulateDifferences(
differences,
[],
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Utilities/__tests__/useRefEffect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function mockEffectRegistry(): {
mockEffectWithoutCleanup: string => () => void,
registry: $ReadOnlyArray<TestEffect | TestEffectCleanup>,
} {
const registry = [];
const registry: Array<TestEffect | TestEffectCleanup> = [];
return {
mockEffect(name: string): () => () => void {
return instance => {
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Utilities/groupByEveryN.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

function groupByEveryN<T>(array: Array<T>, n: number): Array<Array<?T>> {
const result = [];
let temp = [];
let temp: Array<?T> = [];

for (let i = 0; i < array.length; ++i) {
if (i > 0 && i % n === 0) {
Expand Down
4 changes: 3 additions & 1 deletion Libraries/Utilities/stringifySafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export function createStringifySafeWithLimits(limits: {|
maxArrayLimit = Number.POSITIVE_INFINITY,
maxObjectKeysLimit = Number.POSITIVE_INFINITY,
} = limits;
const stack = [];
const stack: Array<
string | {+[string]: mixed} | {'...(truncated keys)...': number},
> = [];
/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
* Flow's LTI update could not be added via codemod */
function replacer(key: string, value: mixed): mixed {
Expand Down
2 changes: 1 addition & 1 deletion packages/hermes-inspector-msggen/src/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Graph {
root.children.add(node);
}

const output = [];
const output: Array<NodeId> = [];
postorder(root, output);

// remove fake root node
Expand Down
6 changes: 3 additions & 3 deletions packages/hermes-inspector-msggen/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function parseDomains(
includeExperimental: Set<string>,
): Descriptor {
const desc = {
types: [],
commands: [],
events: [],
types: ([]: Array<Type>),
commands: ([]: Array<Command>),
events: ([]: Array<Event>),
};

for (const obj of domainObjs) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rn-tester/js/examples/XHR/XHRExampleFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class XHRExampleFetch extends React.Component<any, any> {
return null;
}

const responseHeaders = [];
const responseHeaders: Array<React.Node> = [];
const keys = Object.keys(this.responseHeaders.map);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
Expand Down

0 comments on commit a0ee6fa

Please sign in to comment.