Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-native-babel-transformer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const transform /*: BabelTransformer['transform'] */ = ({
: process.env.BABEL_ENV || 'production';

try {
const babelConfig = {
const babelConfig /*: BabelCoreOptions */ = {
// ES modules require sourceType='module' but OSS may not always want that
sourceType: 'unambiguous',
...buildBabelConfig(filename, options, plugins),
Expand Down
12 changes: 6 additions & 6 deletions packages/react-native-compatibility-check/src/VersionDiffing.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,14 +976,14 @@ function buildNativeModulesDiff(
objectTypeChanges,
);

const newType = {
const newType: CompleteTypeAnnotation = {
type: 'ObjectTypeAnnotation',
properties: [
...newerNativeModule.spec.methods,
...newerNativeModule.spec.eventEmitters,
],
};
const oldType = {
const oldType: CompleteTypeAnnotation = {
type: 'ObjectTypeAnnotation',
properties: [
...olderNativeModule.spec.methods,
Expand Down Expand Up @@ -1073,11 +1073,11 @@ function buildNativeComponentsDiff(
olderCommand => olderCommand.name === command.name,
);

const newCommands = {
const newCommands: CompleteTypeAnnotation = {
type: 'ObjectTypeAnnotation',
properties: [command],
};
const oldCommands =
const oldCommands: ?CompleteTypeAnnotation =
oldCommand != null
? {
type: 'ObjectTypeAnnotation',
Expand Down Expand Up @@ -1123,15 +1123,15 @@ function buildNativeComponentsDiff(

// We have to do this to remove the .defaults from the props and get it into
// standard JavaScript shapes.
const newConvertedProps = {
const newConvertedProps: CompleteTypeAnnotation = {
type: 'ObjectTypeAnnotation',
properties: newerComponent.props.map(prop => ({
name: prop.name,
optional: prop.optional,
typeAnnotation: convertPropToBasicTypes(prop.typeAnnotation),
})),
};
const oldConvertedProps = {
const oldConvertedProps: CompleteTypeAnnotation = {
type: 'ObjectTypeAnnotation',
properties: olderComponent.props.map(prop => ({
name: prop.name,
Expand Down
8 changes: 6 additions & 2 deletions packages/react-native-fantom/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
*/

import type {TestSuiteResult} from '../runtime/setup';
import type {AsyncCommandResult, HermesVariant} from './utils';
import type {
AsyncCommandResult,
ConsoleLogMessage,
HermesVariant,
} from './utils';

import entrypointTemplate from './entrypoint-template';
import * as EnvironmentOptions from './EnvironmentOptions';
Expand Down Expand Up @@ -69,7 +73,7 @@ async function processRNTesterCommandResult(
return;
}

let parsed;
let parsed: ConsoleLogMessage;
try {
parsed = JSON.parse(line);
} catch {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-fantom/runtime/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ function runSpec(spec: Spec): TestCaseResult {
return result;
}

let status;
let status: 'passed' | 'failed' | 'pending';
let error;

const start = Date.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import nullthrows from 'nullthrows';
import * as React from 'react';
import {createRef} from 'react';

const DRAWER_STATES = ['Idle', 'Dragging', 'Settling'];
const DRAWER_STATES = ['Idle', 'Dragging', 'Settling'] as const;

/**
* React component that wraps the platform `DrawerLayout` (Android only). The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,9 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
if (__DEV__ && this.props.style !== undefined) {
// $FlowFixMe[underconstrained-implicit-instantiation]
const style = flattenStyle(this.props.style);
const childLayoutProps = ['alignItems', 'justifyContent'].filter(
const childLayoutProps = (
['alignItems', 'justifyContent'] as const
).filter(
// $FlowFixMe[incompatible-use]
prop => style && style[prop] !== undefined,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const PASSTHROUGH_PROPS = [
'onFocus',
'onLayout',
'testID',
];
] as const;

/**
* Do not use unless you have a very good reason.
Expand Down
24 changes: 13 additions & 11 deletions packages/react-native/Libraries/Core/setUpDeveloperTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ if (__DEV__) {
// TODO(T214991636): Remove legacy Metro log forwarding
if (console._isPolyfilled) {
// We assume full control over the console and send JavaScript logs to Metro.
[
'trace',
'info',
'warn',
'error',
'log',
'group',
'groupCollapsed',
'groupEnd',
'debug',
].forEach(level => {
(
[
'trace',
'info',
'warn',
'error',
'log',
'group',
'groupCollapsed',
'groupEnd',
'debug',
] as const
).forEach(level => {
const originalFunction = console[level];
console[level] = function (...args: $ReadOnlyArray<mixed>) {
HMRClient.log(level, args);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,6 @@ const verticalAlignToTextAlignVerticalMap = {
top: 'top',
bottom: 'bottom',
middle: 'center',
};
} as const;

export default TextImpl;
8 changes: 4 additions & 4 deletions packages/react-native/scripts/ios-prebuild/hermes.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ type HermesEngineSourceType =
*/

const HermesEngineSourceTypes = {
LOCAL_PREBUILT_TARBALL: 'local_prebuilt_tarball',
DOWNLOAD_PREBUILD_TARBALL: 'download_prebuild_tarball',
DOWNLOAD_PREBUILT_NIGHTLY_TARBALL: 'download_prebuilt_nightly_tarball',
};
LOCAL_PREBUILT_TARBALL: 'local_prebuilt_tarball',
DOWNLOAD_PREBUILD_TARBALL: 'download_prebuild_tarball',
DOWNLOAD_PREBUILT_NIGHTLY_TARBALL: 'download_prebuilt_nightly_tarball',
} /*:: as const */;

/**
* Checks if the Hermes artifacts are already downloaded and up to date with the specified version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('createCompositeKeyForProps', () => {
it('excludes non-array and non-object allowlisted props', () => {
const props = {string: 'abc', number: 123, boolean: true, function() {}};
const allowlist = {
string: true,
number: true,
boolean: true,
function: true,
};
string: true,
number: true,
boolean: true,
function: true,
} /*:: as const */;
const compositeKey = createCompositeKeyForProps(props, allowlist);

expect(compositeKey).toEqual(null);
Expand Down Expand Up @@ -53,8 +53,8 @@ describe('createCompositeKeyForProps', () => {
bar: new AnimatedEvent([], {useNativeDriver: true}),
};
const allowlist = {
bar: true,
};
bar: true,
} /*:: as const */;
const compositeKey = createCompositeKeyForProps(props, allowlist);

expect(compositeKey).toEqual({bar: props.bar});
Expand All @@ -69,10 +69,10 @@ describe('createCompositeKeyForProps', () => {
},
};
const allowlist = {
style: {
baz: true,
},
};
style: {
baz: true,
},
} /*:: as const */;
const compositeKey = createCompositeKeyForProps(props, allowlist);

expect(compositeKey).toEqual(null);
Expand All @@ -84,8 +84,8 @@ describe('createCompositeKeyForProps', () => {
bar: new AnimatedValue(1),
};
const allowlist = {
bar: true,
};
bar: true,
} /*:: as const */;
const compositeKey = createCompositeKeyForProps(props, allowlist);

expect(compositeKey).toEqual({bar: props.bar});
Expand All @@ -108,7 +108,7 @@ describe('createCompositeKeyForProps', () => {
const props = {
style: {opacity, transform: [{rotateX: 1}, {rotateY}, {rotateZ: 1}]},
};
const allowlist = {style: {transform: true}};
const allowlist = {style: {transform: true}} /*:: as const */;
const compositeKey = createCompositeKeyForProps(props, allowlist);

expect(compositeKey).toEqual({
Expand All @@ -126,7 +126,7 @@ describe('createCompositeKeyForProps', () => {
const props = {
style: [{opacity: opacityA}, {opacity: opacityB}],
};
const allowlist = {style: {opacity: true}};
const allowlist = {style: {opacity: true}} /*:: as const */;
const compositeKey = createCompositeKeyForProps(props, allowlist);

expect(compositeKey).toEqual({style: {opacity: opacityB}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {TestModule} = NativeModules;
* image with the new one and make sure they are the same.
*/

const TESTS = ['only-if-cached', 'default', 'reload', 'force-cache'];
const TESTS = ['only-if-cached', 'default', 'reload', 'force-cache'] as const;

function ImageCachePolicyTest(): React.Node {
const [state, setState] = useState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const importantForAccessibilityValues = [
'yes',
'no',
'no-hide-descendants',
];
] as const;

type AccessibilityAndroidExampleState = {
count: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const mixBlendModes = [
'saturation',
'color',
'luminosity',
];
] as const;

const examples: Array<RNTesterModuleExample> = mixBlendModes.map(mode => ({
title: mode,
Expand Down
6 changes: 3 additions & 3 deletions packages/rn-tester/js/examples/Modal/ModalPresentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ import * as React from 'react';
import {useCallback, useContext, useState} from 'react';
import {Modal, Platform, StyleSheet, Switch, Text, View} from 'react-native';

const animationTypes = ['slide', 'none', 'fade'];
const animationTypes = ['slide', 'none', 'fade'] as const;
const presentationStyles = [
'fullScreen',
'pageSheet',
'formSheet',
'overFullScreen',
];
] as const;
const supportedOrientations = [
'portrait',
'portrait-upside-down',
'landscape',
'landscape-left',
'landscape-right',
];
] as const;

const backdropColors = ['red', 'blue', undefined];

Expand Down
7 changes: 6 additions & 1 deletion packages/rn-tester/js/examples/Text/TextExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,12 @@ const examples = [
{
title: 'Line Break Strategy',
render: function (): React.Node {
const lineBreakStrategy = ['none', 'standard', 'hangul-word', 'push-out'];
const lineBreakStrategy = [
'none',
'standard',
'hangul-word',
'push-out',
] as const;
const textByCode = {
en: 'lineBreakStrategy lineBreakStrategy lineBreakStrategy lineBreakStrategy',
ko: '한글개행 한글개행 한글개행 한글개행 한글개행 한글개행 한글개행 한글개행',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,21 @@ const examples: Array<RNTesterModuleExample> = [
defaultValue="Font Weight (default)"
style={[styles.singleLine]}
/>
{[
'normal',
'bold',
'900',
800,
'700',
'600',
'500',
'400',
'300',
'200',
'100',
].map(fontWeight => (
{(
[
'normal',
'bold',
'900',
800,
'700',
'600',
'500',
'400',
'300',
'200',
'100',
] as const
).map(fontWeight => (
<ExampleTextInput
defaultValue={`Font Weight (${fontWeight})`}
key={fontWeight}
Expand Down Expand Up @@ -389,7 +391,7 @@ const examples: Array<RNTesterModuleExample> = [
'done',
'previous',
'next',
];
] as const;
const returnKeyLabels = ['Compile', 'React Native'];
const returnKeyExamples = returnKeyTypes.map(type => {
return (
Expand Down
Loading
Loading