Skip to content

Commit c940eb0

Browse files
pietervfacebook-github-bot
authored andcommitted
Add LTI annotations to function params in xplat/js [manually-modified]
Summary: Add annotations to function parameters required for Flow's Local Type Inference project. This codemod prepares the codebase to match Flow's new typechecking algorithm. The new algorithm will make Flow more reliable and predicatable. Reviewed By: bradzacher Differential Revision: D37363351 fbshipit-source-id: a9d3df7db6f9d094ac2ce81aae1f3ab4f62b243a
1 parent e7a4dbc commit c940eb0

File tree

10 files changed

+60
-36
lines changed

10 files changed

+60
-36
lines changed

IntegrationTests/LayoutEventsTest.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
1919

2020
const deepDiffer = require('react-native/Libraries/Utilities/differ/deepDiffer');
2121

22-
function debug(...args) {
22+
function debug(...args: Array<void | Layout | string>) {
2323
// console.log.apply(null, arguments);
2424
}
2525

@@ -119,16 +119,19 @@ class LayoutEventsTest extends React.Component<Props, State> {
119119
}
120120

121121
onViewLayout: (e: LayoutEvent) => void = (e: LayoutEvent) => {
122+
// $FlowFixMe[incompatible-call]
122123
debug('received view layout event\n', e.nativeEvent);
123124
this.setState({viewLayout: e.nativeEvent.layout}, this.checkLayout);
124125
};
125126

126127
onTextLayout: (e: LayoutEvent) => void = (e: LayoutEvent) => {
128+
// $FlowFixMe[incompatible-call]
127129
debug('received text layout event\n', e.nativeEvent);
128130
this.setState({textLayout: e.nativeEvent.layout}, this.checkLayout);
129131
};
130132

131133
onImageLayout: (e: LayoutEvent) => void = (e: LayoutEvent) => {
134+
// $FlowFixMe[incompatible-call]
132135
debug('received image layout event\n', e.nativeEvent);
133136
this.setState({imageLayout: e.nativeEvent.layout}, this.checkLayout);
134137
};

Libraries/Animated/__tests__/bezier-test.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,26 @@
1919

2020
const bezier = require('../bezier');
2121

22-
const identity = function (x) {
22+
const identity = function (x: number) {
2323
return x;
2424
};
2525

26-
function assertClose(a, b, precision = 3) {
26+
function assertClose(a: number, b: number, precision: number = 3) {
2727
expect(a).toBeCloseTo(b, precision);
2828
}
2929

30-
function makeAssertCloseWithPrecision(precision) {
31-
return function (a, b) {
30+
function makeAssertCloseWithPrecision(precision: number) {
31+
return function (a: number, b: number) {
3232
assertClose(a, b, precision);
3333
};
3434
}
3535

36-
function allEquals(be1, be2, samples, assertion) {
36+
function allEquals(
37+
be1: (x: number) => number,
38+
be2: (x: number) => number,
39+
samples: number,
40+
assertion: $FlowFixMe,
41+
) {
3742
if (!assertion) {
3843
assertion = assertClose;
3944
}
@@ -43,8 +48,8 @@ function allEquals(be1, be2, samples, assertion) {
4348
}
4449
}
4550

46-
function repeat(n) {
47-
return function (f) {
51+
function repeat(n: number) {
52+
return function (f: () => void) {
4853
for (let i = 0; i < n; ++i) {
4954
f();
5055
}
@@ -99,7 +104,7 @@ describe('bezier', function () {
99104
d = Math.random();
100105
const easing = bezier(a, b, c, d);
101106
const projected = bezier(b, a, d, c);
102-
const composed = function (x) {
107+
const composed = function (x: number) {
103108
return projected(easing(x));
104109
};
105110
allEquals(identity, composed, 100, makeAssertCloseWithPrecision(2));
@@ -135,7 +140,7 @@ describe('bezier', function () {
135140
c = 1 - a,
136141
d = 1 - b;
137142
const easing = bezier(a, b, c, d);
138-
const sym = function (x) {
143+
const sym = function (x: number) {
139144
return 1 - easing(1 - x);
140145
};
141146
allEquals(easing, sym, 100, makeAssertCloseWithPrecision(2));

Libraries/Lists/FlatList.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
459459
_listRef: ?React.ElementRef<typeof VirtualizedList>;
460460
_virtualizedListPairs: Array<ViewabilityConfigCallbackPair> = [];
461461

462-
_captureRef = ref => {
462+
_captureRef = (ref: ?React.ElementRef<typeof VirtualizedList>) => {
463463
this._listRef = ref;
464464
};
465465

@@ -596,7 +596,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
596596
? 'ListItemComponent'
597597
: 'renderItem';
598598

599-
const renderer = (props): React.Node => {
599+
const renderer = (props: RenderItemProps<ItemT>): React.Node => {
600600
if (ListItemComponent) {
601601
// $FlowFixMe[not-a-component] Component isn't valid
602602
// $FlowFixMe[incompatible-type-arg] Component isn't valid
@@ -625,6 +625,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
625625
<View style={StyleSheet.compose(styles.row, columnWrapperStyle)}>
626626
{item.map((it, kk) => {
627627
const element = renderer({
628+
// $FlowFixMe[incompatible-call]
628629
item: it,
629630
index: index * cols + kk,
630631
separators: info.separators,

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const observe = () => {
5151
};
5252
};
5353

54-
const addLogs = (logs, options) => {
54+
const addLogs = (logs: Array<string>, options: void | {flush: boolean}) => {
5555
logs.forEach(message => {
5656
LogBoxData.addLog({
5757
level: 'warn',
@@ -68,7 +68,10 @@ const addLogs = (logs, options) => {
6868
});
6969
};
7070

71-
const addSoftErrors = (errors, options) => {
71+
const addSoftErrors = (
72+
errors: Array<string>,
73+
options: void | {flush: boolean},
74+
) => {
7275
errors.forEach(error => {
7376
LogBoxData.addException({
7477
message: '',
@@ -89,7 +92,10 @@ const addSoftErrors = (errors, options) => {
8992
});
9093
};
9194

92-
const addFatalErrors = (errors, options) => {
95+
const addFatalErrors = (
96+
errors: Array<$FlowFixMe>,
97+
options: void | {flush: boolean},
98+
) => {
9399
errors.forEach(error => {
94100
LogBoxData.addException({
95101
message: '',
@@ -112,7 +118,7 @@ const addFatalErrors = (errors, options) => {
112118
});
113119
};
114120

115-
const addSyntaxError = options => {
121+
const addSyntaxError = (options: $FlowFixMe) => {
116122
addFatalErrors(
117123
[
118124
{

Libraries/LogBox/UI/__tests__/LogBoxInspectorStackFrames-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const {} = require('../LogBoxInspectorStackFrames');
1818
const LogBoxLog = require('../../Data/LogBoxLog').default;
1919
const render = require('../../../../jest/renderer');
2020

21-
const createLogWithFrames = collapsedOptions => {
21+
const createLogWithFrames = (collapsedOptions: Array<?boolean>) => {
2222
return new LogBoxLog({
2323
level: 'warn',
2424
isComponentError: false,
@@ -32,7 +32,7 @@ const createLogWithFrames = collapsedOptions => {
3232
});
3333
};
3434

35-
const createCollapsedFrames = collapsedOptions => {
35+
const createCollapsedFrames = (collapsedOptions: Array<?boolean>) => {
3636
return collapsedOptions.map(option => ({
3737
column: 1,
3838
file: 'dependency.js',

Libraries/LogBox/__tests__/LogBox-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const LogBoxData = require('../Data/LogBoxData');
1616

1717
declare var console: any;
1818

19-
function mockFilterResult(returnValues) {
19+
function mockFilterResult(returnValues: $FlowFixMe) {
2020
(LogBoxData.checkWarningFilter: any).mockReturnValue({
2121
finalFormat: 'Warning: ...',
2222
forceDialogImmediately: false,

packages/react-native-codegen/src/parsers/flow/components/events.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import type {
1818

1919
function getPropertyType(
2020
name,
21-
optional,
22-
typeAnnotation,
21+
optional: boolean,
22+
typeAnnotation: $FlowFixMe,
2323
): NamedShape<EventTypeAnnotation> {
2424
const type =
2525
typeAnnotation.type === 'GenericTypeAnnotation'
@@ -98,10 +98,10 @@ function getPropertyType(
9898
}
9999

100100
function findEventArgumentsAndType(
101-
typeAnnotation,
102-
types,
103-
bubblingType,
104-
paperName,
101+
typeAnnotation: $FlowFixMe,
102+
types: TypeMap,
103+
bubblingType: void | 'direct' | 'bubble',
104+
paperName: ?$FlowFixMe,
105105
) {
106106
if (!typeAnnotation.id) {
107107
throw new Error("typeAnnotation of event doesn't have a name");
@@ -163,7 +163,7 @@ function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
163163
return getPropertyType(name, optional, typeAnnotation);
164164
}
165165

166-
function getEventArgument(argumentProps, name) {
166+
function getEventArgument(argumentProps, name: $FlowFixMe) {
167167
return {
168168
type: 'ObjectTypeAnnotation',
169169
properties: argumentProps.map(buildPropertiesForEvent),

packages/react-native-codegen/src/parsers/typescript/components/events.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818

1919
function getPropertyType(
2020
name,
21-
optional,
21+
optional: boolean,
2222
typeAnnotation,
2323
): NamedShape<EventTypeAnnotation> {
2424
const type =
@@ -118,10 +118,10 @@ function getPropertyType(
118118
}
119119

120120
function findEventArgumentsAndType(
121-
typeAnnotation,
122-
types,
123-
bubblingType,
124-
paperName,
121+
typeAnnotation: $FlowFixMe,
122+
types: TypeMap,
123+
bubblingType: void | 'direct' | 'bubble',
124+
paperName: ?$FlowFixMe,
125125
) {
126126
if (!typeAnnotation.typeName) {
127127
throw new Error("typeAnnotation of event doesn't have a name");
@@ -177,7 +177,7 @@ function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
177177
return getPropertyType(name, optional, typeAnnotation);
178178
}
179179

180-
function getEventArgument(argumentProps, name) {
180+
function getEventArgument(argumentProps, name: $FlowFixMe) {
181181
return {
182182
type: 'ObjectTypeAnnotation',
183183
properties: argumentProps.map(buildPropertiesForEvent),

packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,10 +1148,19 @@ class DisplayOptionsStatusExample extends React.Component<{}> {
11481148
}
11491149
}
11501150

1151-
function DisplayOptionStatusExample({optionName, optionChecker, notification}) {
1151+
function DisplayOptionStatusExample({
1152+
optionName,
1153+
optionChecker,
1154+
notification,
1155+
}: {
1156+
notification: string,
1157+
optionChecker: () => Promise<boolean>,
1158+
optionName: string,
1159+
}) {
11521160
const [statusEnabled, setStatusEnabled] = React.useState(false);
11531161
React.useEffect(() => {
11541162
const listener = AccessibilityInfo.addEventListener(
1163+
// $FlowFixMe[prop-missing]
11551164
notification,
11561165
setStatusEnabled,
11571166
);

packages/rn-tester/js/examples/Appearance/AppearanceExample.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ColorSchemeSubscription extends React.Component<
5252
}
5353
}
5454

55-
const ThemedContainer = props => (
55+
const ThemedContainer = (props: {children: React.Node}) => (
5656
<RNTesterThemeContext.Consumer>
5757
{theme => {
5858
return (
@@ -69,7 +69,7 @@ const ThemedContainer = props => (
6969
</RNTesterThemeContext.Consumer>
7070
);
7171

72-
const ThemedText = props => (
72+
const ThemedText = (props: {children: React.Node}) => (
7373
<RNTesterThemeContext.Consumer>
7474
{theme => {
7575
return <Text style={{color: theme.LabelColor}}>{props.children}</Text>;
@@ -89,7 +89,7 @@ const AppearanceViaHook = () => {
8989
);
9090
};
9191

92-
const ColorShowcase = props => (
92+
const ColorShowcase = (props: {themeName: string}) => (
9393
<RNTesterThemeContext.Consumer>
9494
{theme => {
9595
return (

0 commit comments

Comments
 (0)