Skip to content

Commit 5c369aa

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Add annotations to fix future natural inference errors in xplat/js: 6/n (#53894)
Summary: Pull Request resolved: #53894 Changelog: [Internal] Reviewed By: marcoww6 Differential Revision: D83000736 fbshipit-source-id: 3ba5c59d9b2f7b967c0dccd24a73056430153bdc
1 parent 2065c31 commit 5c369aa

11 files changed

Lines changed: 82 additions & 53 deletions

File tree

flow-typed/environment/node.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,30 +3057,30 @@ type util$InspectOptions = {
30573057
};
30583058

30593059
declare type util$ParseArgsOption =
3060-
| {|
3060+
| $ReadOnly<{|
30613061
type: 'boolean',
30623062
multiple?: false,
30633063
short?: string,
30643064
default?: boolean,
3065-
|}
3066-
| {|
3065+
|}>
3066+
| $ReadOnly<{|
30673067
type: 'boolean',
30683068
multiple: true,
30693069
short?: string,
30703070
default?: Array<boolean>,
3071-
|}
3072-
| {|
3071+
|}>
3072+
| $ReadOnly<{|
30733073
type: 'string',
30743074
multiple?: false,
30753075
short?: string,
30763076
default?: string,
3077-
|}
3078-
| {|
3077+
|}>
3078+
| $ReadOnly<{|
30793079
type: 'string',
30803080
multiple: true,
30813081
short?: string,
30823082
default?: Array<string>,
3083-
|};
3083+
|}>;
30843084

30853085
type util$ParseArgsOptionToValue<TOption> = TOption['type'] extends 'boolean'
30863086
? TOption['multiple'] extends true
@@ -3137,7 +3137,7 @@ declare module 'util' {
31373137
declare function stripVTControlCharacters(str: string): string;
31383138

31393139
declare function parseArgs<
3140-
TOptions: {[string]: util$ParseArgsOption} = {||},
3140+
TOptions: {+[string]: util$ParseArgsOption} = {||},
31413141
>(config: {|
31423142
args?: Array<string>,
31433143
options?: TOptions,

packages/debugger-shell/src/electron/index.flow.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ app.setVersion(pkg.version + '-' + buildInfo.revision);
2525
const {
2626
values: {version = false},
2727
} = util.parseArgs({
28-
options: {version: {type: 'boolean'}},
28+
options: {
29+
version: {type: 'boolean'},
30+
},
2931
args: process.argv.slice(app.isPackaged ? 1 : 2),
3032
strict: false,
3133
});

packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function combineSchemas(
4747
}
4848
return merged;
4949
},
50-
{modules: {}},
50+
{modules: {} /*:: as SchemaType['modules'] */},
5151
);
5252

5353
return {

packages/react-native/scripts/featureflags/print.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ function getPurposeString(purpose: string): string {
3737
}
3838

3939
function compareFeatureFlags(
40-
[keyA, valueA]: [string, {Purpose: string, ...}],
41-
[keyB, valueB]: [string, {Purpose: string, ...}],
40+
[keyA, valueA]: $ReadOnly<[string, $ReadOnly<{Purpose: string, ...}>]>,
41+
[keyB, valueB]: $ReadOnly<[string, $ReadOnly<{Purpose: string, ...}>]>,
4242
): number {
4343
const purposeA = PURPOSE_ORDER.indexOf(valueA.Purpose);
4444
const purposeB = PURPOSE_ORDER.indexOf(valueB.Purpose);

packages/rn-tester/IntegrationTests/ImageCachePolicyTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const {TestModule} = NativeModules;
3131
const TESTS = ['only-if-cached', 'default', 'reload', 'force-cache'] as const;
3232

3333
function ImageCachePolicyTest(): React.Node {
34-
const [state, setState] = useState({
34+
const [state, setState] = useState<{[string]: ?boolean}>({
3535
'only-if-cached': undefined,
3636
default: undefined,
3737
reload: undefined,

packages/rn-tester/js/examples/Filter/FilterExample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function StaticViewAndImageWithState(props: Props): React.Node {
6868

6969
const styles = StyleSheet.create({
7070
blurWithShadow: {
71-
filter: [{blur: 10}],
71+
filter: [{blur: 10 as string | number}],
7272
boxShadow: '0 0 10px 10px black',
7373
overflow: 'hidden',
7474
backgroundColor: 'pink',

packages/rn-tester/js/examples/Transform/TransformExample.js

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

1111
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
12+
import type {AnimatedNode} from 'react-native/Libraries/Animated/AnimatedExports';
1213

1314
import * as React from 'react';
1415
import {useEffect, useRef, useState} from 'react';
@@ -226,7 +227,16 @@ const styles = StyleSheet.create({
226227
height: 50,
227228
position: 'absolute',
228229
top: 0,
229-
transform: [{translate: [200, 350]}, {scale: 2.5}, {rotate: '-0.2rad'}],
230+
transform: [
231+
{
232+
translate: [200, 350] as [
233+
number | string | AnimatedNode,
234+
number | string | AnimatedNode,
235+
],
236+
},
237+
{scale: 2.5},
238+
{rotate: '-0.2rad'},
239+
],
230240
width: 100,
231241
},
232242
box5: {
@@ -238,7 +248,16 @@ const styles = StyleSheet.create({
238248
width: 50,
239249
},
240250
box5Transform: {
241-
transform: [{translate: [-50, 35]}, {rotate: '50deg'}, {scale: 2}],
251+
transform: [
252+
{
253+
translate: [-50, 35] as [
254+
number | string | AnimatedNode,
255+
number | string | AnimatedNode,
256+
],
257+
},
258+
{rotate: '50deg'},
259+
{scale: 2},
260+
],
242261
},
243262
box6: {
244263
backgroundColor: 'salmon',

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

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,16 @@ describe('VirtualizedSectionList', () => {
9797
ListEmptyComponent={() => <empty />}
9898
ListFooterComponent={() => <footer />}
9999
ListHeaderComponent={() => <header />}
100-
sections={[
101-
{
102-
title: 's1',
103-
data: new Array<void>(5)
104-
.fill()
105-
.map((_, ii) => ({id: String(ii)})) as Array<{id: string}>,
106-
},
107-
]}
100+
sections={
101+
[
102+
{
103+
title: 's1',
104+
data: new Array<void>(5)
105+
.fill()
106+
.map((_, ii) => ({id: String(ii)})) as Array<{id: string}>,
107+
},
108+
] as Array<SectionBase<{id: string}>>
109+
}
108110
getItem={(data, key) => data[key]}
109111
getItemCount={data => data.length}
110112
getItemLayout={({index}) => ({
@@ -165,21 +167,25 @@ describe('VirtualizedSectionList', () => {
165167
component = ReactTestRenderer.create(
166168
<VirtualizedSectionList
167169
// $FlowFixMe[incompatible-type]
168-
sections={[
169-
{title: 'outer', data: [{key: 'outer0'}, {key: 'outer1'}]},
170-
]}
170+
sections={
171+
[
172+
{title: 'outer', data: [{key: 'outer0'}, {key: 'outer1'}]},
173+
] as Array<SectionBase<{key: string}>>
174+
}
171175
renderItem={outerInfo => (
172176
<VirtualizedSectionList
173-
sections={[
174-
// $FlowFixMe[incompatible-type]
175-
{
176-
title: 'inner',
177-
data: [
178-
{key: outerInfo.item.key + ':inner0'},
179-
{key: outerInfo.item.key + ':inner1'},
180-
],
181-
},
182-
]}
177+
sections={
178+
[
179+
// $FlowFixMe[incompatible-type]
180+
{
181+
title: 'inner',
182+
data: [
183+
{key: outerInfo.item.key + ':inner0'},
184+
{key: outerInfo.item.key + ':inner1'},
185+
],
186+
},
187+
] as Array<SectionBase<{key: string}>>
188+
}
183189
horizontal={outerInfo.item.key === 'outer1'}
184190
renderItem={innerInfo => {
185191
return <item title={innerInfo.item.key} />;
@@ -206,18 +212,20 @@ describe('VirtualizedSectionList', () => {
206212
await ReactTestRenderer.act(() => {
207213
component = ReactTestRenderer.create(
208214
<VirtualizedSectionList
209-
sections={[
210-
// $FlowFixMe[incompatible-type]
211-
{
212-
title: 's1',
213-
data: [{key: 'i1.1'}, {key: 'i1.2'}, {key: 'i1.3'}],
214-
},
215-
// $FlowFixMe[incompatible-type]
216-
{
217-
title: 's2',
218-
data: [{key: 'i2.1'}, {key: 'i2.2'}, {key: 'i2.3'}],
219-
},
220-
]}
215+
sections={
216+
[
217+
// $FlowFixMe[incompatible-type]
218+
{
219+
title: 's1',
220+
data: [{key: 'i1.1'}, {key: 'i1.2'}, {key: 'i1.3'}],
221+
},
222+
// $FlowFixMe[incompatible-type]
223+
{
224+
title: 's2',
225+
data: [{key: 'i2.1'}, {key: 'i2.2'}, {key: 'i2.3'}],
226+
},
227+
] as Array<SectionBase<{key: string}>>
228+
}
221229
renderItem={({item}) => <item value={item.key} />}
222230
getItem={(data, key) => data[key]}
223231
getItemCount={data => data.length}

scripts/releases/upload-release-assets-for-dotslash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async function main() {
5656
force: {type: 'boolean', default: false},
5757
dryRun: {type: 'boolean', default: false},
5858
help: {type: 'boolean'},
59-
},
59+
} /*:: as {[string]: util$ParseArgsOption} */,
6060
});
6161

6262
if (help) {

scripts/releases/validate-dotslash-artifacts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async function main() {
3131
allowPositionals: true,
3232
options: {
3333
help: {type: 'boolean'},
34-
},
34+
} /*:: as {[string]: util$ParseArgsOption} */,
3535
});
3636

3737
if (help) {

0 commit comments

Comments
 (0)