Skip to content

Commit 50ca7e5

Browse files
panagosg7facebook-github-bot
authored andcommitted
manual annotations in preparation of natural inference rollout in react-native, tools, etc.
Summary: The Flow team is improving the way Flow infers type for primitive literals. This diff prepares the codebase for the new behavior by adding type annotations, or annotations of the form `'abc' as const`. Changelog: [internal] Reviewed By: marcoww6 Differential Revision: D75188179 fbshipit-source-id: be50990f23f79cf2d8dae7576af5190218adcafe
1 parent 12ced22 commit 50ca7e5

21 files changed

Lines changed: 99 additions & 76 deletions

File tree

packages/react-native-babel-transformer/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const transform /*: BabelTransformer['transform'] */ = ({
188188
: process.env.BABEL_ENV || 'production';
189189

190190
try {
191-
const babelConfig = {
191+
const babelConfig /*: BabelCoreOptions */ = {
192192
// ES modules require sourceType='module' but OSS may not always want that
193193
sourceType: 'unambiguous',
194194
...buildBabelConfig(filename, options, plugins),

packages/react-native-compatibility-check/src/VersionDiffing.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -976,14 +976,14 @@ function buildNativeModulesDiff(
976976
objectTypeChanges,
977977
);
978978

979-
const newType = {
979+
const newType: CompleteTypeAnnotation = {
980980
type: 'ObjectTypeAnnotation',
981981
properties: [
982982
...newerNativeModule.spec.methods,
983983
...newerNativeModule.spec.eventEmitters,
984984
],
985985
};
986-
const oldType = {
986+
const oldType: CompleteTypeAnnotation = {
987987
type: 'ObjectTypeAnnotation',
988988
properties: [
989989
...olderNativeModule.spec.methods,
@@ -1073,11 +1073,11 @@ function buildNativeComponentsDiff(
10731073
olderCommand => olderCommand.name === command.name,
10741074
);
10751075

1076-
const newCommands = {
1076+
const newCommands: CompleteTypeAnnotation = {
10771077
type: 'ObjectTypeAnnotation',
10781078
properties: [command],
10791079
};
1080-
const oldCommands =
1080+
const oldCommands: ?CompleteTypeAnnotation =
10811081
oldCommand != null
10821082
? {
10831083
type: 'ObjectTypeAnnotation',
@@ -1123,15 +1123,15 @@ function buildNativeComponentsDiff(
11231123

11241124
// We have to do this to remove the .defaults from the props and get it into
11251125
// standard JavaScript shapes.
1126-
const newConvertedProps = {
1126+
const newConvertedProps: CompleteTypeAnnotation = {
11271127
type: 'ObjectTypeAnnotation',
11281128
properties: newerComponent.props.map(prop => ({
11291129
name: prop.name,
11301130
optional: prop.optional,
11311131
typeAnnotation: convertPropToBasicTypes(prop.typeAnnotation),
11321132
})),
11331133
};
1134-
const oldConvertedProps = {
1134+
const oldConvertedProps: CompleteTypeAnnotation = {
11351135
type: 'ObjectTypeAnnotation',
11361136
properties: olderComponent.props.map(prop => ({
11371137
name: prop.name,

packages/react-native-fantom/runner/runner.js

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

1111
import type {TestSuiteResult} from '../runtime/setup';
12-
import type {AsyncCommandResult, HermesVariant} from './utils';
12+
import type {
13+
AsyncCommandResult,
14+
ConsoleLogMessage,
15+
HermesVariant,
16+
} from './utils';
1317

1418
import entrypointTemplate from './entrypoint-template';
1519
import * as EnvironmentOptions from './EnvironmentOptions';
@@ -69,7 +73,7 @@ async function processRNTesterCommandResult(
6973
return;
7074
}
7175

72-
let parsed;
76+
let parsed: ConsoleLogMessage;
7377
try {
7478
parsed = JSON.parse(line);
7579
} catch {

packages/react-native-fantom/runtime/setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ function runSpec(spec: Spec): TestCaseResult {
320320
return result;
321321
}
322322

323-
let status;
323+
let status: 'passed' | 'failed' | 'pending';
324324
let error;
325325

326326
const start = Date.now();

packages/react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import nullthrows from 'nullthrows';
3030
import * as React from 'react';
3131
import {createRef} from 'react';
3232

33-
const DRAWER_STATES = ['Idle', 'Dragging', 'Settling'];
33+
const DRAWER_STATES = ['Idle', 'Dragging', 'Settling'] as const;
3434

3535
/**
3636
* React component that wraps the platform `DrawerLayout` (Android only). The

packages/react-native/Libraries/Components/ScrollView/ScrollView.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,9 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
16461646
if (__DEV__ && this.props.style !== undefined) {
16471647
// $FlowFixMe[underconstrained-implicit-instantiation]
16481648
const style = flattenStyle(this.props.style);
1649-
const childLayoutProps = ['alignItems', 'justifyContent'].filter(
1649+
const childLayoutProps = (
1650+
['alignItems', 'justifyContent'] as const
1651+
).filter(
16501652
// $FlowFixMe[incompatible-use]
16511653
prop => style && style[prop] !== undefined,
16521654
);

packages/react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const PASSTHROUGH_PROPS = [
152152
'onFocus',
153153
'onLayout',
154154
'testID',
155-
];
155+
] as const;
156156

157157
/**
158158
* Do not use unless you have a very good reason.

packages/react-native/Libraries/Core/setUpDeveloperTools.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ if (__DEV__) {
2323
// TODO(T214991636): Remove legacy Metro log forwarding
2424
if (console._isPolyfilled) {
2525
// We assume full control over the console and send JavaScript logs to Metro.
26-
[
27-
'trace',
28-
'info',
29-
'warn',
30-
'error',
31-
'log',
32-
'group',
33-
'groupCollapsed',
34-
'groupEnd',
35-
'debug',
36-
].forEach(level => {
26+
(
27+
[
28+
'trace',
29+
'info',
30+
'warn',
31+
'error',
32+
'log',
33+
'group',
34+
'groupCollapsed',
35+
'groupEnd',
36+
'debug',
37+
] as const
38+
).forEach(level => {
3739
const originalFunction = console[level];
3840
console[level] = function (...args: $ReadOnlyArray<mixed>) {
3941
HMRClient.log(level, args);

packages/react-native/Libraries/Text/Text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,6 @@ const verticalAlignToTextAlignVerticalMap = {
545545
top: 'top',
546546
bottom: 'bottom',
547547
middle: 'center',
548-
};
548+
} as const;
549549

550550
export default TextImpl;

packages/react-native/scripts/ios-prebuild/hermes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ type HermesEngineSourceType =
9797
*/
9898

9999
const HermesEngineSourceTypes = {
100-
LOCAL_PREBUILT_TARBALL: 'local_prebuilt_tarball',
101-
DOWNLOAD_PREBUILD_TARBALL: 'download_prebuild_tarball',
102-
DOWNLOAD_PREBUILT_NIGHTLY_TARBALL: 'download_prebuilt_nightly_tarball',
103-
};
100+
LOCAL_PREBUILT_TARBALL: 'local_prebuilt_tarball',
101+
DOWNLOAD_PREBUILD_TARBALL: 'download_prebuild_tarball',
102+
DOWNLOAD_PREBUILT_NIGHTLY_TARBALL: 'download_prebuilt_nightly_tarball',
103+
} /*:: as const */;
104104

105105
/**
106106
* Checks if the Hermes artifacts are already downloaded and up to date with the specified version.

0 commit comments

Comments
 (0)