diff --git a/packages/react-native-babel-transformer/src/index.js b/packages/react-native-babel-transformer/src/index.js index 26cab6f928eb..42cb9ed97b8a 100644 --- a/packages/react-native-babel-transformer/src/index.js +++ b/packages/react-native-babel-transformer/src/index.js @@ -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), diff --git a/packages/react-native-compatibility-check/src/VersionDiffing.js b/packages/react-native-compatibility-check/src/VersionDiffing.js index 93664a18f20f..ac659730fb8a 100644 --- a/packages/react-native-compatibility-check/src/VersionDiffing.js +++ b/packages/react-native-compatibility-check/src/VersionDiffing.js @@ -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, @@ -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', @@ -1123,7 +1123,7 @@ 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, @@ -1131,7 +1131,7 @@ function buildNativeComponentsDiff( typeAnnotation: convertPropToBasicTypes(prop.typeAnnotation), })), }; - const oldConvertedProps = { + const oldConvertedProps: CompleteTypeAnnotation = { type: 'ObjectTypeAnnotation', properties: olderComponent.props.map(prop => ({ name: prop.name, diff --git a/packages/react-native-fantom/runner/runner.js b/packages/react-native-fantom/runner/runner.js index 7d071f0cabda..415c3e1cfa51 100644 --- a/packages/react-native-fantom/runner/runner.js +++ b/packages/react-native-fantom/runner/runner.js @@ -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'; @@ -69,7 +73,7 @@ async function processRNTesterCommandResult( return; } - let parsed; + let parsed: ConsoleLogMessage; try { parsed = JSON.parse(line); } catch { diff --git a/packages/react-native-fantom/runtime/setup.js b/packages/react-native-fantom/runtime/setup.js index 3f21826f3b69..b7d724a61b95 100644 --- a/packages/react-native-fantom/runtime/setup.js +++ b/packages/react-native-fantom/runtime/setup.js @@ -320,7 +320,7 @@ function runSpec(spec: Spec): TestCaseResult { return result; } - let status; + let status: 'passed' | 'failed' | 'pending'; let error; const start = Date.now(); diff --git a/packages/react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js b/packages/react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js index df181e34670e..01ac874db452 100644 --- a/packages/react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +++ b/packages/react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js @@ -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 diff --git a/packages/react-native/Libraries/Components/ScrollView/ScrollView.js b/packages/react-native/Libraries/Components/ScrollView/ScrollView.js index dac0a5b0103d..f43a3c2e72c6 100644 --- a/packages/react-native/Libraries/Components/ScrollView/ScrollView.js +++ b/packages/react-native/Libraries/Components/ScrollView/ScrollView.js @@ -1646,7 +1646,9 @@ class ScrollView extends React.Component { 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, ); diff --git a/packages/react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js b/packages/react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js index 4fe0ac146838..d375fe7b899f 100755 --- a/packages/react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js +++ b/packages/react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js @@ -152,7 +152,7 @@ const PASSTHROUGH_PROPS = [ 'onFocus', 'onLayout', 'testID', -]; +] as const; /** * Do not use unless you have a very good reason. diff --git a/packages/react-native/Libraries/Core/setUpDeveloperTools.js b/packages/react-native/Libraries/Core/setUpDeveloperTools.js index 334f2a4d3df1..965b29f880c8 100644 --- a/packages/react-native/Libraries/Core/setUpDeveloperTools.js +++ b/packages/react-native/Libraries/Core/setUpDeveloperTools.js @@ -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) { HMRClient.log(level, args); diff --git a/packages/react-native/Libraries/Text/Text.js b/packages/react-native/Libraries/Text/Text.js index 6713d1882b90..ad49c363ef51 100644 --- a/packages/react-native/Libraries/Text/Text.js +++ b/packages/react-native/Libraries/Text/Text.js @@ -545,6 +545,6 @@ const verticalAlignToTextAlignVerticalMap = { top: 'top', bottom: 'bottom', middle: 'center', -}; +} as const; export default TextImpl; diff --git a/packages/react-native/scripts/ios-prebuild/hermes.js b/packages/react-native/scripts/ios-prebuild/hermes.js index 4d1586dd6271..0c4fc60c8289 100644 --- a/packages/react-native/scripts/ios-prebuild/hermes.js +++ b/packages/react-native/scripts/ios-prebuild/hermes.js @@ -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. diff --git a/packages/react-native/src/private/animated/__tests__/createAnimatedPropsMemoHook-test.js b/packages/react-native/src/private/animated/__tests__/createAnimatedPropsMemoHook-test.js index db3013c4ea52..bfc648ac9ee1 100644 --- a/packages/react-native/src/private/animated/__tests__/createAnimatedPropsMemoHook-test.js +++ b/packages/react-native/src/private/animated/__tests__/createAnimatedPropsMemoHook-test.js @@ -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); @@ -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}); @@ -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); @@ -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}); @@ -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({ @@ -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}}); diff --git a/packages/rn-tester/IntegrationTests/ImageCachePolicyTest.js b/packages/rn-tester/IntegrationTests/ImageCachePolicyTest.js index d188e55b2b6e..b5216951c70b 100644 --- a/packages/rn-tester/IntegrationTests/ImageCachePolicyTest.js +++ b/packages/rn-tester/IntegrationTests/ImageCachePolicyTest.js @@ -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({ diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityAndroidExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityAndroidExample.js index 6b41f4357903..d6db0a05f78c 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityAndroidExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityAndroidExample.js @@ -21,7 +21,7 @@ const importantForAccessibilityValues = [ 'yes', 'no', 'no-hide-descendants', -]; +] as const; type AccessibilityAndroidExampleState = { count: number, diff --git a/packages/rn-tester/js/examples/MixBlendMode/MixBlendModeExample.js b/packages/rn-tester/js/examples/MixBlendMode/MixBlendModeExample.js index 63f823defed8..5a7592c8fc1f 100644 --- a/packages/rn-tester/js/examples/MixBlendMode/MixBlendModeExample.js +++ b/packages/rn-tester/js/examples/MixBlendMode/MixBlendModeExample.js @@ -131,7 +131,7 @@ const mixBlendModes = [ 'saturation', 'color', 'luminosity', -]; +] as const; const examples: Array = mixBlendModes.map(mode => ({ title: mode, diff --git a/packages/rn-tester/js/examples/Modal/ModalPresentation.js b/packages/rn-tester/js/examples/Modal/ModalPresentation.js index 38f697a684a1..fe310ba7b222 100644 --- a/packages/rn-tester/js/examples/Modal/ModalPresentation.js +++ b/packages/rn-tester/js/examples/Modal/ModalPresentation.js @@ -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]; diff --git a/packages/rn-tester/js/examples/Text/TextExample.ios.js b/packages/rn-tester/js/examples/Text/TextExample.ios.js index 33312e9eb92f..0780cafa78b3 100644 --- a/packages/rn-tester/js/examples/Text/TextExample.ios.js +++ b/packages/rn-tester/js/examples/Text/TextExample.ios.js @@ -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: '한글개행 한글개행 한글개행 한글개행 한글개행 한글개행 한글개행 한글개행', diff --git a/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js b/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js index 025215a1df80..323e23e4ba6d 100644 --- a/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js +++ b/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js @@ -119,19 +119,21 @@ const examples: Array = [ 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 => ( = [ 'done', 'previous', 'next', - ]; + ] as const; const returnKeyLabels = ['Compile', 'React Native']; const returnKeyExamples = returnKeyTypes.map(type => { return ( diff --git a/packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js b/packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js index eadeccba1097..ddb83a17439c 100644 --- a/packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js +++ b/packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js @@ -373,7 +373,7 @@ const textInputExamples: Array = [ 'phone-pad', 'decimal-pad', 'ascii-capable-number-pad', - ]; + ] as const; const examples = keyboardTypesWithDoneButton.map(type => { return ( @@ -434,7 +434,7 @@ const textInputExamples: Array = [ { title: 'Keyboard appearance', render: function (): React.Node { - const keyboardAppearance = ['default', 'light', 'dark']; + const keyboardAppearance = ['default', 'light', 'dark'] as const; const examples = keyboardAppearance.map(type => { return ( @@ -460,7 +460,7 @@ const textInputExamples: Array = [ 'yahoo', 'done', 'emergency-call', - ]; + ] as const; const examples = returnKeyTypes.map(type => { return ( @@ -525,7 +525,7 @@ const textInputExamples: Array = [ 'while-editing', 'unless-editing', 'always', - ]; + ] as const; const examples = clearButtonModes.map(mode => { return ( @@ -918,7 +918,12 @@ const textInputExamples: Array = [ { 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: '한글개행한글개행 한글개행한글개행 한글개행한글개행 한글개행한글개행 한글개행한글개행 한글개행한글개행', @@ -996,7 +1001,7 @@ const textInputExamples: Array = [ 'head', 'middle', 'tail', - ]; + ] as const; const textByCode = { en: 'verylongtext-dummydummydummydummydummydummydummydummydummydummydummydummy', ko: '한글개행한글개행-한글개행한글개행한글개행한글개행한글개행한글개행한글개행한글개행한글개행한글개행', diff --git a/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js b/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js index a0e33122e65c..3f31e064c0ee 100644 --- a/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js +++ b/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js @@ -1011,7 +1011,7 @@ module.exports = ([ 'web-search', 'ascii-capable-number-pad', 'numeric', - ]; + ] as const; const examples = keyboardTypes.map(type => { return ( @@ -1035,7 +1035,7 @@ module.exports = ([ 'search', 'email', 'url', - ]; + ] as const; const examples = inputMode.map(mode => { return ( @@ -1064,7 +1064,7 @@ module.exports = ([ 'previous', 'search', 'send', - ]; + ] as const; const examples = enterKeyHintTypesHints.map(hint => { return ( diff --git a/packages/rn-tester/js/utils/testerStateUtils.js b/packages/rn-tester/js/utils/testerStateUtils.js index df8137bc58e5..640cd68dcd99 100644 --- a/packages/rn-tester/js/utils/testerStateUtils.js +++ b/packages/rn-tester/js/utils/testerStateUtils.js @@ -22,7 +22,7 @@ export const Screens = { COMPONENTS: 'components', APIS: 'apis', PLAYGROUNDS: 'playgrounds', -}; +} as const; export const initialNavigationState: RNTesterNavigationState = { activeModuleKey: null, diff --git a/scripts/utils/monorepo.js b/scripts/utils/monorepo.js index 2cf9ac37583f..b6eeb2325c18 100644 --- a/scripts/utils/monorepo.js +++ b/scripts/utils/monorepo.js @@ -117,7 +117,10 @@ async function updatePackageJson( packageJson.version = newPackageVersions[packageName]; } - for (const dependencyField of ['dependencies', 'devDependencies']) { + for (const dependencyField of [ + 'dependencies', + 'devDependencies', + ] /*:: as const */) { const deps = packageJson[dependencyField]; if (deps == null) {