From 7051a07c637bc221889eba5017d62600cca7701d Mon Sep 17 00:00:00 2001 From: Marco Wang Date: Tue, 13 Jan 2026 20:33:09 -0800 Subject: [PATCH] Transform $ReadOnlyArray to ReadonlyArray 17/n (#55109) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55109 We are transforming the following utility types to be more consistent with typescript and better AI integration: * `$NonMaybeType` -> `NonNullable` * `$ReadOnly` -> `Readonly` * `$ReadOnlyArray` -> `ReadonlyArray` * `$ReadOnlyMap` -> `ReadonlyMap` * `$ReadOnlySet` -> `ReadonlySet` * `$Keys` -> `keyof` * `$Values` -> `Values` * `mixed` -> `unknown` See details in https://fb.workplace.com/groups/flowlang/permalink/1837907750148213/. drop-conflicts Command: `js1 flow-runner codemod flow/transformUtilityType --legacy-type='$ReadOnlyArray'` Reviewed By: SamChou19815 Differential Revision: D90402950 fbshipit-source-id: d338ad7997728d40457b1199c3bd5dcd245a39c3 --- flow-typed/environment/node.js | 30 ++++++++--------- flow-typed/npm/@expo/spawn-async_v1.x.x.js | 2 +- .../cli-server-api_v19.x.x.js | 2 +- flow-typed/npm/babel-traverse_v7.x.x.js | 6 ++-- flow-typed/npm/babel_v7.x.x.js | 2 +- flow-typed/npm/execa_v5.x.x.js | 8 ++--- flow-typed/npm/jest.js | 20 ++++++------ flow-typed/npm/listr2_v8.x.x.js | 2 +- flow-typed/npm/listr_v14.x.x.js | 2 +- .../src/commands/bundle/assetCatalogIOS.js | 2 +- .../commands/bundle/createKeepFileAsync.js | 2 +- .../bundle/filterPlatformAssetScales.js | 4 +-- .../src/commands/bundle/saveAssets.js | 2 +- .../start/OpenDebuggerKeyboardHandler.js | 4 +-- .../src/commands/start/middleware.js | 2 +- .../src/utils/createDevMiddlewareLogger.js | 2 +- .../src/utils/parseKeyValueParamArray.js | 2 +- .../core-cli-utils/src/private/android.js | 2 +- packages/core-cli-utils/src/private/app.js | 9 ++---- packages/core-cli-utils/src/private/apple.js | 2 +- packages/core-cli-utils/src/private/utils.js | 2 +- .../src/inspector-proxy/CdpDebugLogging.js | 2 +- .../src/inspector-proxy/Device.js | 2 +- .../src/inspector-proxy/types.js | 8 ++--- packages/polyfills/error-guard.js | 6 ++-- .../src/__mocks__/test-helpers.js | 6 ++-- .../react-native-codegen/src/CodegenSchema.js | 32 +++++++++---------- .../src/SchemaValidator.js | 2 +- .../src/generators/Utils.js | 2 +- .../components/ComponentsGeneratorUtils.js | 6 ++-- .../src/generators/components/CppHelpers.js | 8 ++--- .../components/GenerateEventEmitterCpp.js | 16 +++++----- .../components/GenerateEventEmitterH.js | 10 +++--- .../generators/components/GeneratePropsH.js | 18 +++++------ .../GeneratePropsJavaPojo/PojoCollector.js | 10 +++--- .../components/GenerateViewConfigJs.js | 2 +- .../src/generators/modules/GenerateModuleH.js | 4 +-- .../modules/GenerateModuleJniCpp.js | 8 ++--- .../GenerateModuleObjCpp/StructCollector.js | 6 ++-- .../GenerateModuleObjCpp/serializeMethod.js | 6 ++-- .../source/serializeModule.js | 14 ++++---- .../src/parsers/__tests__/error-utils-test.js | 2 +- .../src/parsers/error-utils.js | 8 ++--- .../src/parsers/errors.js | 6 ++-- .../src/parsers/flow/components/commands.js | 6 ++-- .../flow/components/componentsUtils.js | 4 +-- .../src/parsers/flow/components/events.js | 4 +-- .../__tests__/module-parser-e2e-test.js | 6 ++-- .../src/parsers/flow/parser.js | 20 ++++++------ .../src/parsers/parser.js | 12 +++---- .../src/parsers/parserMock.js | 20 ++++++------ .../src/parsers/parsers-commons.js | 14 ++++---- 52 files changed, 186 insertions(+), 193 deletions(-) diff --git a/flow-typed/environment/node.js b/flow-typed/environment/node.js index ba5e9ed9f1c..6f9d2a0cb80 100644 --- a/flow-typed/environment/node.js +++ b/flow-typed/environment/node.js @@ -1887,7 +1887,7 @@ declare module 'fs' { */ exclude?: | ((fileName: Node$Conditional) => boolean) - | $ReadOnlyArray, + | ReadonlyArray, ... }>; @@ -1905,12 +1905,12 @@ declare module 'fs' { * @since v22.0.0 */ declare function glob( - pattern: string | $ReadOnlyArray, + pattern: string | ReadonlyArray, callback: (err: ?ErrnoError, matches: Array) => void, ): void; declare function glob( - pattern: string | $ReadOnlyArray, + pattern: string | ReadonlyArray, options: GlobOptions, callback: ( err: ?ErrnoError, @@ -1928,7 +1928,7 @@ declare module 'fs' { * @returns paths of files that match the pattern. */ declare function globSync( - pattern: string | $ReadOnlyArray, + pattern: string | ReadonlyArray, options?: GlobOptions, ): Node$Conditional, Array>; @@ -2142,7 +2142,7 @@ declare module 'fs' { mtime: number | string | Date, ): Promise, glob( - pattern: string | $ReadOnlyArray, + pattern: string | ReadonlyArray, options?: GlobOptions, ): Node$Conditional< WithFileTypes, @@ -2292,7 +2292,7 @@ declare class http$Agent<+SocketT = net$Socket> { constructor(options: http$agentOptions): void; destroy(): void; // $FlowFixMe[incompatible-variance] - freeSockets: {[name: string]: $ReadOnlyArray, ...}; + freeSockets: {[name: string]: ReadonlyArray, ...}; getName(options: { host: string, port: number, @@ -2302,9 +2302,9 @@ declare class http$Agent<+SocketT = net$Socket> { maxFreeSockets: number; maxSockets: number; // $FlowFixMe[incompatible-variance] - requests: {[name: string]: $ReadOnlyArray>, ...}; + requests: {[name: string]: ReadonlyArray>, ...}; // $FlowFixMe[incompatible-variance] - sockets: {[name: string]: $ReadOnlyArray, ...}; + sockets: {[name: string]: ReadonlyArray, ...}; } declare class http$IncomingMessage @@ -2968,11 +2968,11 @@ declare module 'perf_hooks' { ) => void; declare export class PerformanceObserver { - static supportedEntryTypes: $ReadOnlyArray; + static supportedEntryTypes: ReadonlyArray; constructor(callback: PerformanceObserverCallback): this; observe( options: Readonly<{ - entryTypes?: $ReadOnlyArray, + entryTypes?: ReadonlyArray, type?: EntryType, buffered?: boolean, }>, @@ -3461,7 +3461,7 @@ declare module 'stream' { options?: StreamPipelineOptions, ): Promise, pipeline( - streams: $ReadOnlyArray, + streams: ReadonlyArray, options?: StreamPipelineOptions, ): Promise, ... @@ -3900,7 +3900,7 @@ declare module 'url' { }; declare type url$URLPatternResult = { - inputs: $ReadOnlyArray, + inputs: ReadonlyArray, protocol: url$URLPatternComponentResult, username: url$URLPatternComponentResult, password: url$URLPatternComponentResult, @@ -4104,8 +4104,8 @@ declare module 'util' { declare type util$DiffEntry = [operation: -1 | 0 | 1, value: string]; declare function diff( - actual: string | $ReadOnlyArray, - expected: string | $ReadOnlyArray, + actual: string | ReadonlyArray, + expected: string | ReadonlyArray, ): Array; declare function getSystemErrorMessage(err: number): string; @@ -4224,7 +4224,7 @@ declare module 'util' { | ForegroundColors | BackgroundColors | Modifiers - | $ReadOnlyArray, + | ReadonlyArray, text: string, options?: Readonly<{ stream?: ?stream$Stream, diff --git a/flow-typed/npm/@expo/spawn-async_v1.x.x.js b/flow-typed/npm/@expo/spawn-async_v1.x.x.js index 45c6187c9aa..1e60d38129d 100644 --- a/flow-typed/npm/@expo/spawn-async_v1.x.x.js +++ b/flow-typed/npm/@expo/spawn-async_v1.x.x.js @@ -38,7 +38,7 @@ declare module '@expo/spawn-async' { declare function spawnAsync( command: string, - args?: $ReadOnlyArray, + args?: ReadonlyArray, options?: SpawnOptions, ): SpawnPromise; diff --git a/flow-typed/npm/@react-native-community/cli-server-api_v19.x.x.js b/flow-typed/npm/@react-native-community/cli-server-api_v19.x.x.js index c6307e1b13c..33f2f7d9fba 100644 --- a/flow-typed/npm/@react-native-community/cli-server-api_v19.x.x.js +++ b/flow-typed/npm/@react-native-community/cli-server-api_v19.x.x.js @@ -13,7 +13,7 @@ declare module '@react-native-community/cli-server-api' { declare type MiddlewareOptions = { host?: string, - watchFolders: $ReadOnlyArray, + watchFolders: ReadonlyArray, port: number, }; diff --git a/flow-typed/npm/babel-traverse_v7.x.x.js b/flow-typed/npm/babel-traverse_v7.x.x.js index 344099df669..0726aef6da8 100644 --- a/flow-typed/npm/babel-traverse_v7.x.x.js +++ b/flow-typed/npm/babel-traverse_v7.x.x.js @@ -390,9 +390,7 @@ declare module '@babel/traverse' { * Earliest is defined as being "before" all the other nodes in terms of list container * position and visiting key. */ - getEarliestCommonAncestorFrom( - paths: $ReadOnlyArray>, - ): NodePath<>; + getEarliestCommonAncestorFrom(paths: ReadonlyArray>): NodePath<>; /** * Get the earliest path in the tree where the provided `paths` intersect. @@ -400,7 +398,7 @@ declare module '@babel/traverse' { * TODO: Possible optimisation target. */ getDeepestCommonAncestorFrom( - paths: $ReadOnlyArray>, + paths: ReadonlyArray>, filter?: ( lastCommon: BabelNode, lastCommonIndex: number, diff --git a/flow-typed/npm/babel_v7.x.x.js b/flow-typed/npm/babel_v7.x.x.js index a1f665cd5bc..f9d293c16c1 100644 --- a/flow-typed/npm/babel_v7.x.x.js +++ b/flow-typed/npm/babel_v7.x.x.js @@ -1027,7 +1027,7 @@ declare module '@babel/core' { declare export var template: Template; declare export var traverse: Traverse; declare export var types: Types; - declare export var DEFAULT_EXTENSIONS: $ReadOnlyArray; + declare export var DEFAULT_EXTENSIONS: ReadonlyArray; declare export function buildExternalHelpers( whitelist?: Array, diff --git a/flow-typed/npm/execa_v5.x.x.js b/flow-typed/npm/execa_v5.x.x.js index db3f61779d1..c54a07291e9 100644 --- a/flow-typed/npm/execa_v5.x.x.js +++ b/flow-typed/npm/execa_v5.x.x.js @@ -37,7 +37,7 @@ declare module 'execa' { shell?: boolean | string, stderr?: ?StdIoOption, stdin?: ?StdIoOption, - stdio?: 'pipe' | 'ignore' | 'inherit' | $ReadOnlyArray, + stdio?: 'pipe' | 'ignore' | 'inherit' | ReadonlyArray, stdout?: ?StdIoOption, stripEof?: boolean, timeout?: number, @@ -90,7 +90,7 @@ declare module 'execa' { declare interface Execa { ( file: string, - args?: $ReadOnlyArray, + args?: ReadonlyArray, options?: Readonly, ): ExecaPromise; (file: string, options?: Readonly): ExecaPromise; @@ -100,13 +100,13 @@ declare module 'execa' { node( path: string, - args?: $ReadOnlyArray, + args?: ReadonlyArray, options?: Readonly, ): void; sync( file: string, - args?: $ReadOnlyArray, + args?: ReadonlyArray, options?: Readonly, ): SyncResult; sync(file: string, options?: Readonly): SyncResult; diff --git a/flow-typed/npm/jest.js b/flow-typed/npm/jest.js index 1bfe9618ce6..ae645e711e8 100644 --- a/flow-typed/npm/jest.js +++ b/flow-typed/npm/jest.js @@ -13,7 +13,7 @@ // MODIFIED: Added ESLint suppression comment - no-unused-vars doesn't understand declaration files -type JestMockFn, TReturn> = { +type JestMockFn, TReturn> = { (...args: TArguments): TReturn, /** * An object for introspecting mock calls @@ -768,7 +768,7 @@ interface JestExpectType { /** * */ - toHaveProperty(propPath: string | $ReadOnlyArray, value?: any): void; + toHaveProperty(propPath: string | ReadonlyArray, value?: any): void; /** * Use .toMatch to check that a string matches a regular expression or string. */ @@ -881,7 +881,7 @@ type JestObjectType = { * implementation. */ // MODIFIED: Added defaults to type arguments. - fn = $ReadOnlyArray, TReturn = any>( + fn = ReadonlyArray, TReturn = any>( implementation?: (...args: TArguments) => TReturn, ): JestMockFn, /** @@ -1045,11 +1045,11 @@ declare var describe: { */ each( ...table: - | $ReadOnlyArray<$ReadOnlyArray | unknown> - | [$ReadOnlyArray, string] + | ReadonlyArray | unknown> + | [ReadonlyArray, string] ): ( name: JestTestName, - fn?: (...args: $ReadOnlyArray) => ?Promise, + fn?: (...args: ReadonlyArray) => ?Promise, timeout?: number, ) => void, ... @@ -1136,8 +1136,8 @@ declare var it: { */ each( ...table: - | $ReadOnlyArray<$ReadOnlyArray | unknown> - | [$ReadOnlyArray, string] + | ReadonlyArray | unknown> + | [ReadonlyArray, string] ): ( name: JestTestName, fn?: (...args: Array) => ?Promise, @@ -1252,13 +1252,13 @@ declare var expect: { any(value: unknown): JestAsymmetricEqualityType, anything(): any, // MODIFIED: Array -> $ReadOnlyArray - arrayContaining(value: $ReadOnlyArray): Array, + arrayContaining(value: ReadonlyArray): Array, objectContaining(value: Object): Object, /** Matches any received string that contains the exact expected string. */ stringContaining(value: string): string, stringMatching(value: string | RegExp): string, not: { - arrayContaining: (value: $ReadOnlyArray) => Array, + arrayContaining: (value: ReadonlyArray) => Array, objectContaining: (value: {...}) => Object, stringContaining: (value: string) => string, stringMatching: (value: string | RegExp) => string, diff --git a/flow-typed/npm/listr2_v8.x.x.js b/flow-typed/npm/listr2_v8.x.x.js index 6bee2c703ee..b072831f66e 100644 --- a/flow-typed/npm/listr2_v8.x.x.js +++ b/flow-typed/npm/listr2_v8.x.x.js @@ -55,7 +55,7 @@ declare module 'listr2' { options?: Options, ): void; add(task: TaskSpec): this; - add(tasks: $ReadOnlyArray>): this; + add(tasks: ReadonlyArray>): this; run(ctx?: ContextT): Promise; } } diff --git a/flow-typed/npm/listr_v14.x.x.js b/flow-typed/npm/listr_v14.x.x.js index bc2a6bc7c19..8372dc9caf3 100644 --- a/flow-typed/npm/listr_v14.x.x.js +++ b/flow-typed/npm/listr_v14.x.x.js @@ -55,7 +55,7 @@ declare module 'listr' { options?: Options, ): void; add(task: TaskSpec): this; - add(tasks: $ReadOnlyArray>): this; + add(tasks: ReadonlyArray>): this; run(ctx?: ContextT): Promise; } } diff --git a/packages/community-cli-plugin/src/commands/bundle/assetCatalogIOS.js b/packages/community-cli-plugin/src/commands/bundle/assetCatalogIOS.js index 33f013741a9..eefc3c6d5ad 100644 --- a/packages/community-cli-plugin/src/commands/bundle/assetCatalogIOS.js +++ b/packages/community-cli-plugin/src/commands/bundle/assetCatalogIOS.js @@ -31,7 +31,7 @@ type ImageSet = { export function getImageSet( catalogDir: string, asset: AssetData, - scales: $ReadOnlyArray, + scales: ReadonlyArray, ): ImageSet { const fileName = assetPathUtils.getResourceIdentifier(asset); return { diff --git a/packages/community-cli-plugin/src/commands/bundle/createKeepFileAsync.js b/packages/community-cli-plugin/src/commands/bundle/createKeepFileAsync.js index 405df8a4605..479c1bdf014 100644 --- a/packages/community-cli-plugin/src/commands/bundle/createKeepFileAsync.js +++ b/packages/community-cli-plugin/src/commands/bundle/createKeepFileAsync.js @@ -15,7 +15,7 @@ import fs from 'fs'; import path from 'path'; async function createKeepFileAsync( - assets: $ReadOnlyArray, + assets: ReadonlyArray, outputDirectory: string, ): Promise { if (!assets.length) { diff --git a/packages/community-cli-plugin/src/commands/bundle/filterPlatformAssetScales.js b/packages/community-cli-plugin/src/commands/bundle/filterPlatformAssetScales.js index 139fa4ff61b..0c78dd87e3c 100644 --- a/packages/community-cli-plugin/src/commands/bundle/filterPlatformAssetScales.js +++ b/packages/community-cli-plugin/src/commands/bundle/filterPlatformAssetScales.js @@ -14,8 +14,8 @@ const ALLOWED_SCALES: {[key: string]: number[]} = { function filterPlatformAssetScales( platform: string, - scales: $ReadOnlyArray, -): $ReadOnlyArray { + scales: ReadonlyArray, +): ReadonlyArray { const whitelist: number[] = ALLOWED_SCALES[platform]; if (!whitelist) { return scales; diff --git a/packages/community-cli-plugin/src/commands/bundle/saveAssets.js b/packages/community-cli-plugin/src/commands/bundle/saveAssets.js index 2a759a0540f..83a8e139cb2 100644 --- a/packages/community-cli-plugin/src/commands/bundle/saveAssets.js +++ b/packages/community-cli-plugin/src/commands/bundle/saveAssets.js @@ -29,7 +29,7 @@ type CopiedFiles = { }; async function saveAssets( - assets: $ReadOnlyArray, + assets: ReadonlyArray, platform: string, assetsDest?: string, assetCatalogDest?: string, diff --git a/packages/community-cli-plugin/src/commands/start/OpenDebuggerKeyboardHandler.js b/packages/community-cli-plugin/src/commands/start/OpenDebuggerKeyboardHandler.js index 14affb2664a..75afc25ce13 100644 --- a/packages/community-cli-plugin/src/commands/start/OpenDebuggerKeyboardHandler.js +++ b/packages/community-cli-plugin/src/commands/start/OpenDebuggerKeyboardHandler.js @@ -22,7 +22,7 @@ type PageDescription = Readonly<{ export default class OpenDebuggerKeyboardHandler { #devServerUrl: string; #reporter: TerminalReporter; - #targetsShownForSelection: ?$ReadOnlyArray = null; + #targetsShownForSelection: ?ReadonlyArray = null; constructor({ devServerUrl, @@ -82,7 +82,7 @@ export default class OpenDebuggerKeyboardHandler { if (res.status !== 200) { throw new Error(`Unexpected status code: ${res.status}`); } - const targets = (await res.json()) as $ReadOnlyArray; + const targets = (await res.json()) as ReadonlyArray; if (!Array.isArray(targets)) { throw new Error('Expected array.'); } diff --git a/packages/community-cli-plugin/src/commands/start/middleware.js b/packages/community-cli-plugin/src/commands/start/middleware.js index 81007f6ab41..806d8c39353 100644 --- a/packages/community-cli-plugin/src/commands/start/middleware.js +++ b/packages/community-cli-plugin/src/commands/start/middleware.js @@ -43,7 +43,7 @@ const communityMiddlewareFallback = { createDevServerMiddleware: (params: { host?: string, port: number, - watchFolders: $ReadOnlyArray, + watchFolders: ReadonlyArray, }): MiddlewareReturn => ({ // FIXME: Several features will break without community middleware and // should be migrated into core. diff --git a/packages/community-cli-plugin/src/utils/createDevMiddlewareLogger.js b/packages/community-cli-plugin/src/utils/createDevMiddlewareLogger.js index 869052a047a..6975b9f925b 100644 --- a/packages/community-cli-plugin/src/utils/createDevMiddlewareLogger.js +++ b/packages/community-cli-plugin/src/utils/createDevMiddlewareLogger.js @@ -10,7 +10,7 @@ import type {TerminalReporter} from 'metro'; -type LoggerFn = (...message: $ReadOnlyArray) => void; +type LoggerFn = (...message: ReadonlyArray) => void; /** * Create a dev-middleware logger object that will emit logs via Metro's diff --git a/packages/community-cli-plugin/src/utils/parseKeyValueParamArray.js b/packages/community-cli-plugin/src/utils/parseKeyValueParamArray.js index cc2b94822f6..92356a6bba1 100644 --- a/packages/community-cli-plugin/src/utils/parseKeyValueParamArray.js +++ b/packages/community-cli-plugin/src/utils/parseKeyValueParamArray.js @@ -9,7 +9,7 @@ */ export default function parseKeyValueParamArray( - keyValueArray: $ReadOnlyArray, + keyValueArray: ReadonlyArray, ): Record { const result = {}; diff --git a/packages/core-cli-utils/src/private/android.js b/packages/core-cli-utils/src/private/android.js index 6ef6c1be4b6..c9ea7a7e59e 100644 --- a/packages/core-cli-utils/src/private/android.js +++ b/packages/core-cli-utils/src/private/android.js @@ -17,7 +17,7 @@ import execa from 'execa'; type AndroidBuildMode = 'Debug' | 'Release'; type Path = string; -type Args = $ReadOnlyArray; +type Args = ReadonlyArray; type Config = { cwd: Path, diff --git a/packages/core-cli-utils/src/private/app.js b/packages/core-cli-utils/src/private/app.js index 990f76a9441..0491ae577cd 100644 --- a/packages/core-cli-utils/src/private/app.js +++ b/packages/core-cli-utils/src/private/app.js @@ -75,16 +75,13 @@ function getNodePackagePath(packageName: string): string { return require.resolve(packageName, {cwd: [process.cwd(), ...module.paths]}); } -function metro(...args: $ReadOnlyArray): ExecaPromise { +function metro(...args: ReadonlyArray): ExecaPromise { log(`🚇 metro ${args.join(' ')} `); return execa('npx', ['--offline', 'metro', ...args]); } export const tasks = { - bundle: ( - options: BundlerOptions, - ...args: $ReadOnlyArray - ): Bundle => { + bundle: (options: BundlerOptions, ...args: ReadonlyArray): Bundle => { const steps: Bundle = { /* eslint-disable sort-keys */ validate: task(FIRST, 'Check if Metro is available', () => { @@ -117,7 +114,7 @@ type Bundle = { const bundleApp = ( options: BundlerOptions, - ...metroArgs: $ReadOnlyArray + ...metroArgs: ReadonlyArray ) => { if (options.outputJsBundle === options.outputBundle) { throw new Error('outputJsBundle and outputBundle cannot be the same.'); diff --git a/packages/core-cli-utils/src/private/apple.js b/packages/core-cli-utils/src/private/apple.js index 317b60fbe61..691a6147ba1 100644 --- a/packages/core-cli-utils/src/private/apple.js +++ b/packages/core-cli-utils/src/private/apple.js @@ -144,7 +144,7 @@ export const tasks = { // 2. Build the iOS app using a setup environment build: ( options: AppleBuildOptions, - ...args: $ReadOnlyArray + ...args: ReadonlyArray ): { validate: Task, hasPodsInstalled: Task, diff --git a/packages/core-cli-utils/src/private/utils.js b/packages/core-cli-utils/src/private/utils.js index f41bbb8a8d2..78cadf5ebaa 100644 --- a/packages/core-cli-utils/src/private/utils.js +++ b/packages/core-cli-utils/src/private/utils.js @@ -55,7 +55,7 @@ export function isOnPath(dep: string, description: string): PathCheckResult { } export function assertDependencies( - ...deps: $ReadOnlyArray> + ...deps: ReadonlyArray> ) { for (const {found, dep, description} of deps) { if (!found) { diff --git a/packages/dev-middleware/src/inspector-proxy/CdpDebugLogging.js b/packages/dev-middleware/src/inspector-proxy/CdpDebugLogging.js index f30a9c9f9da..056c07f76f0 100644 --- a/packages/dev-middleware/src/inspector-proxy/CdpDebugLogging.js +++ b/packages/dev-middleware/src/inspector-proxy/CdpDebugLogging.js @@ -95,7 +95,7 @@ export default class CdpDebugLogging { ); } if (timeout == null) { - timeout = setTimeout<$ReadOnlyArray>(() => { + timeout = setTimeout>(() => { debug( '%s %s CDP messages of size %s MB %s in the last %ss.', getCDPLogPrefix(destination), diff --git a/packages/dev-middleware/src/inspector-proxy/Device.js b/packages/dev-middleware/src/inspector-proxy/Device.js index 568d0e63448..ad29acf8668 100644 --- a/packages/dev-middleware/src/inspector-proxy/Device.js +++ b/packages/dev-middleware/src/inspector-proxy/Device.js @@ -282,7 +282,7 @@ export default class Device { return this.#app; } - getPagesList(): $ReadOnlyArray { + getPagesList(): ReadonlyArray { if (this.#lastConnectedLegacyReactNativePage) { return [...this.#pages.values(), this.#createSyntheticPage()]; } else { diff --git a/packages/dev-middleware/src/inspector-proxy/types.js b/packages/dev-middleware/src/inspector-proxy/types.js index d30125ffdf6..16abf599495 100644 --- a/packages/dev-middleware/src/inspector-proxy/types.js +++ b/packages/dev-middleware/src/inspector-proxy/types.js @@ -88,7 +88,7 @@ export type GetPagesRequest = {event: 'getPages'}; // Response to GetPagesRequest containing a list of page infos. export type GetPagesResponse = { event: 'getPages', - payload: $ReadOnlyArray, + payload: ReadonlyArray, }; // Union type for all possible messages sent from device to Inspector Proxy. @@ -141,12 +141,12 @@ export type JSONSerializable = | number | string | null - | $ReadOnlyArray + | ReadonlyArray | {+[string]: JSONSerializable}; export type DeepReadOnly = - T extends $ReadOnlyArray - ? $ReadOnlyArray> + T extends ReadonlyArray + ? ReadonlyArray> : T extends {...} ? {+[K in keyof T]: DeepReadOnly} : T; diff --git a/packages/polyfills/error-guard.js b/packages/polyfills/error-guard.js index 3ba6327de4b..433bb27a3be 100644 --- a/packages/polyfills/error-guard.js +++ b/packages/polyfills/error-guard.js @@ -52,7 +52,7 @@ const ErrorUtils = { * Condition roll out. See https://fburl.com/workplace/1v97vimq. */ _globalHandler && _globalHandler(error, true); }, - applyWithGuard, TOut>( + applyWithGuard, TOut>( fun: Fn, context?: ?unknown, args?: ?TArgs, @@ -75,7 +75,7 @@ const ErrorUtils = { } return null; }, - applyWithGuardIfNeeded, TOut>( + applyWithGuardIfNeeded, TOut>( fun: Fn, context?: ?unknown, args?: ?TArgs, @@ -94,7 +94,7 @@ const ErrorUtils = { inGuard(): boolean { return !!_inGuard; }, - guard, TOut>( + guard, TOut>( fun: Fn, name?: ?string, context?: ?unknown, diff --git a/packages/react-native-babel-preset/src/__mocks__/test-helpers.js b/packages/react-native-babel-preset/src/__mocks__/test-helpers.js index e29d18f6cb8..ff84ab5a753 100644 --- a/packages/react-native-babel-preset/src/__mocks__/test-helpers.js +++ b/packages/react-native-babel-preset/src/__mocks__/test-helpers.js @@ -18,7 +18,7 @@ const t = require('@babel/types'); const nullthrows = require('nullthrows'); function makeTransformOptions( - plugins: $ReadOnlyArray, + plugins: ReadonlyArray, options: OptionsT, ): BabelCoreOptions { return { @@ -53,7 +53,7 @@ function validateOutputAst(ast: BabelNode) { } function transformToAst( - plugins: $ReadOnlyArray, + plugins: ReadonlyArray, code: string, options: T, ): BabelNodeFile { @@ -68,7 +68,7 @@ function transformToAst( function transform( code: string, - plugins: $ReadOnlyArray, + plugins: ReadonlyArray, options: ?EntryOptions, ): string { return generate(transformToAst(plugins, code, options)).code; diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 7013735b3dc..56149dcad59 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -70,14 +70,14 @@ export type VoidTypeAnnotation = Readonly<{ export type ObjectTypeAnnotation<+T> = Readonly<{ type: 'ObjectTypeAnnotation', - properties: $ReadOnlyArray>, + properties: ReadonlyArray>, // metadata for objects that generated from interfaces - baseTypes?: $ReadOnlyArray, + baseTypes?: ReadonlyArray, }>; export type UnionTypeAnnotation<+T> = Readonly<{ type: 'UnionTypeAnnotation', - types: $ReadOnlyArray, + types: ReadonlyArray, }>; export type MixedTypeAnnotation = Readonly<{ @@ -91,7 +91,7 @@ export type EventEmitterTypeAnnotation = Readonly<{ type FunctionTypeAnnotation<+P, +R> = Readonly<{ type: 'FunctionTypeAnnotation', - params: $ReadOnlyArray>, + params: ReadonlyArray>, returnTypeAnnotation: R, }>; @@ -110,10 +110,10 @@ export type ComponentSchema = Readonly<{ export type ComponentShape = Readonly<{ ...OptionsShape, - extendsProps: $ReadOnlyArray, - events: $ReadOnlyArray, - props: $ReadOnlyArray>, - commands: $ReadOnlyArray>, + extendsProps: ReadonlyArray, + events: ReadonlyArray, + props: ReadonlyArray>, + commands: ReadonlyArray>, }>; export type OptionsShape = Readonly<{ @@ -124,7 +124,7 @@ export type OptionsShape = Readonly<{ // Does not check for new name paperComponentName?: string, // Use for components that are not used on other platforms. - excludedPlatforms?: $ReadOnlyArray, + excludedPlatforms?: ReadonlyArray, // Use for components currently being renamed in paper // Will use new name if it is available and fallback to this name paperComponentNameDeprecated?: string, @@ -171,7 +171,7 @@ export type ComponentArrayTypeAnnotation = ArrayTypeAnnotation< | Readonly<{ type: 'StringEnumTypeAnnotation', default: string, - options: $ReadOnlyArray, + options: ReadonlyArray, }> | ObjectTypeAnnotation | ReservedPropTypeAnnotation @@ -220,12 +220,12 @@ export type PropTypeAnnotation = | Readonly<{ type: 'StringEnumTypeAnnotation', default: string, - options: $ReadOnlyArray, + options: ReadonlyArray, }> | Readonly<{ type: 'Int32EnumTypeAnnotation', default: number, - options: $ReadOnlyArray, + options: ReadonlyArray, }> | ReservedPropTypeAnnotation | ObjectTypeAnnotation @@ -283,12 +283,12 @@ export type NativeModuleSchema = Readonly<{ // Use for modules that are not used on other platforms. // TODO: It's clearer to define `restrictedToPlatforms` instead, but // `excludedPlatforms` is used here to be consistent with ComponentSchema. - excludedPlatforms?: $ReadOnlyArray, + excludedPlatforms?: ReadonlyArray, }>; type NativeModuleSpec = Readonly<{ - eventEmitters: $ReadOnlyArray, - methods: $ReadOnlyArray, + eventEmitters: ReadonlyArray, + methods: ReadonlyArray, }>; export type NativeModuleEventEmitterShape = @@ -353,7 +353,7 @@ export type NativeModuleEnumDeclarationWithMembers = { name: string, type: 'EnumDeclarationWithMembers', memberType: NativeModuleEnumMemberType, - members: $ReadOnlyArray, + members: ReadonlyArray, }; export type NativeModuleGenericObjectTypeAnnotation = Readonly<{ diff --git a/packages/react-native-codegen/src/SchemaValidator.js b/packages/react-native-codegen/src/SchemaValidator.js index dc59d9cd77b..04ca2d53fe1 100644 --- a/packages/react-native-codegen/src/SchemaValidator.js +++ b/packages/react-native-codegen/src/SchemaValidator.js @@ -14,7 +14,7 @@ import type {SchemaType} from './CodegenSchema'; const nullthrows = require('nullthrows'); -function getErrors(schema: SchemaType): $ReadOnlyArray { +function getErrors(schema: SchemaType): ReadonlyArray { const errors = new Set(); // Map of component name -> Array of module names diff --git a/packages/react-native-codegen/src/generators/Utils.js b/packages/react-native-codegen/src/generators/Utils.js index 59227b34d29..7fcd65eeeb1 100644 --- a/packages/react-native-codegen/src/generators/Utils.js +++ b/packages/react-native-codegen/src/generators/Utils.js @@ -67,7 +67,7 @@ class HeterogeneousUnionError extends Error { function parseValidUnionType( annotation: NativeModuleUnionTypeAnnotation, ): ValidUnionType { - const isUnionOfType = (types: $ReadOnlyArray): boolean => { + const isUnionOfType = (types: ReadonlyArray): boolean => { return annotation.types.every(memberTypeAnnotation => types.includes(memberTypeAnnotation.type), ); diff --git a/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js b/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js index 68ecdca3bd0..20d01db6861 100644 --- a/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js +++ b/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js @@ -46,7 +46,7 @@ function getNativeTypeFromAnnotation( | ReservedPropTypeAnnotation | { +default: string, - +options: $ReadOnlyArray, + +options: ReadonlyArray, +type: 'StringEnumTypeAnnotation', } | { @@ -54,7 +54,7 @@ function getNativeTypeFromAnnotation( +type: 'ArrayTypeAnnotation', }, }, - nameParts: $ReadOnlyArray, + nameParts: ReadonlyArray, ): string { const typeAnnotation = prop.typeAnnotation; @@ -214,7 +214,7 @@ const convertVarValueToPointer = (type: string, value: string): string => { }; function getLocalImports( - properties: $ReadOnlyArray>, + properties: ReadonlyArray>, ): Set { const imports: Set = new Set(); diff --git a/packages/react-native-codegen/src/generators/components/CppHelpers.js b/packages/react-native-codegen/src/generators/components/CppHelpers.js index c3b6f3dbba0..d027eb2b153 100644 --- a/packages/react-native-codegen/src/generators/components/CppHelpers.js +++ b/packages/react-native-codegen/src/generators/components/CppHelpers.js @@ -120,8 +120,8 @@ function getCppArrayTypeForAnnotation( function getImports( properties: - | $ReadOnlyArray> - | $ReadOnlyArray>, + | ReadonlyArray> + | ReadonlyArray>, ): Set { const imports: Set = new Set(); @@ -183,13 +183,13 @@ function getImports( return imports; } -function generateEventStructName(parts: $ReadOnlyArray = []): string { +function generateEventStructName(parts: ReadonlyArray = []): string { return parts.map(toSafeCppString).join(''); } function generateStructName( componentName: string, - parts: $ReadOnlyArray = [], + parts: ReadonlyArray = [], ): string { const additional = parts.map(toSafeCppString).join(''); return `${componentName}${additional}Struct`; diff --git a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js index 75f1d8cc9ed..31ca6ebe7ae 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js +++ b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js @@ -99,7 +99,7 @@ void ${className}EventEmitter::${eventName}() const { function generateSetter( variableName: string, propertyName: string, - propertyParts: $ReadOnlyArray, + propertyParts: ReadonlyArray, usingEvent: boolean, valueMapper: string => string = value => value, ) { @@ -114,7 +114,7 @@ function generateSetter( function generateObjectSetter( variableName: string, propertyName: string, - propertyParts: $ReadOnlyArray, + propertyParts: ReadonlyArray, typeAnnotation: ObjectTypeAnnotation, extraIncludes: Set, usingEvent: boolean, @@ -151,7 +151,7 @@ function setValueAtIndex( function generateArraySetter( variableName: string, propertyName: string, - propertyParts: $ReadOnlyArray, + propertyParts: ReadonlyArray, elementType: EventTypeAnnotation, extraIncludes: Set, usingEvent: boolean, @@ -184,7 +184,7 @@ function handleArrayElementType( propertyName: string, indexVariable: string, loopLocalVariable: string, - propertyParts: $ReadOnlyArray, + propertyParts: ReadonlyArray, extraIncludes: Set, usingEvent: boolean, ): string { @@ -249,7 +249,7 @@ function convertObjectTypeArray( propertyName: string, indexVariable: string, loopLocalVariable: string, - propertyParts: $ReadOnlyArray, + propertyParts: ReadonlyArray, objectTypeAnnotation: ObjectTypeAnnotation, extraIncludes: Set, ): string { @@ -268,7 +268,7 @@ function convertArrayTypeArray( propertyName: string, indexVariable: string, loopLocalVariable: string, - propertyParts: $ReadOnlyArray, + propertyParts: ReadonlyArray, eventTypeAnnotation: EventTypeAnnotation, extraIncludes: Set, usingEvent: boolean, @@ -296,8 +296,8 @@ function convertArrayTypeArray( function generateSetters( parentPropertyName: string, - properties: $ReadOnlyArray>, - propertyParts: $ReadOnlyArray, + properties: ReadonlyArray>, + propertyParts: ReadonlyArray, extraIncludes: Set, usingEvent: boolean = true, ): string { diff --git a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js index 3f1ec849071..00c6c8cf0ea 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js @@ -117,7 +117,7 @@ static char const *toString(const ${enumName} value) { function getNativeTypeFromAnnotation( componentName: string, eventProperty: NamedShape, - nameParts: $ReadOnlyArray, + nameParts: ReadonlyArray, ): string { const {typeAnnotation} = eventProperty; switch (typeAnnotation.type) { @@ -156,7 +156,7 @@ function getNativeTypeFromAnnotation( } function generateEnum( structs: StructsMap, - options: $ReadOnlyArray, + options: ReadonlyArray, nameParts: Array, ) { const structName = generateEventStructName(nameParts); @@ -186,7 +186,7 @@ function handleGenerateStructForArray( name: string, componentName: string, elementType: EventTypeAnnotation, - nameParts: $ReadOnlyArray, + nameParts: ReadonlyArray, ): void { if (elementType.type === 'ObjectTypeAnnotation') { generateStruct( @@ -219,8 +219,8 @@ function handleGenerateStructForArray( function generateStruct( structs: StructsMap, componentName: string, - nameParts: $ReadOnlyArray, - properties: $ReadOnlyArray>, + nameParts: ReadonlyArray, + properties: ReadonlyArray>, ): void { const structNameParts = nameParts; const structName = generateEventStructName(structNameParts); diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js index 9c9083b4a42..6b909918eb3 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js @@ -351,7 +351,7 @@ function convertValueToEnumOption(value: string): string { function generateArrayEnumString( componentName: string, name: string, - options: $ReadOnlyArray, + options: ReadonlyArray, ): string { const enumName = getEnumName(componentName, name); @@ -393,7 +393,7 @@ function generateStringEnum( ) { const typeAnnotation = prop.typeAnnotation; if (typeAnnotation.type === 'StringEnumTypeAnnotation') { - const values: $ReadOnlyArray = typeAnnotation.options; + const values: ReadonlyArray = typeAnnotation.options; const enumName = getEnumName(componentName, prop.name); const fromCases = values @@ -431,7 +431,7 @@ function generateIntEnum( ) { const typeAnnotation = prop.typeAnnotation; if (typeAnnotation.type === 'Int32EnumTypeAnnotation') { - const values: $ReadOnlyArray = typeAnnotation.options; + const values: ReadonlyArray = typeAnnotation.options; const enumName = getEnumName(componentName, prop.name); const fromCases = values @@ -527,8 +527,8 @@ function generateEnumString( function generatePropsString( componentName: string, - props: $ReadOnlyArray>, - nameParts: $ReadOnlyArray, + props: ReadonlyArray>, + nameParts: ReadonlyArray, generateOptionalProperties?: boolean = false, ) { return props @@ -557,7 +557,7 @@ function generatePropsString( } function getExtendsImports( - extendsProps: $ReadOnlyArray, + extendsProps: ReadonlyArray, ): Set { const imports: Set = new Set(); @@ -605,7 +605,7 @@ function generateStructsForComponent( function generateStructs( componentName: string, - properties: $ReadOnlyArray>, + properties: ReadonlyArray>, nameParts: Array, generateOptionalObjectProperties?: boolean = false, ): StructsMap { @@ -726,8 +726,8 @@ function generateStructs( function generateStruct( structs: StructsMap, componentName: string, - nameParts: $ReadOnlyArray, - properties: $ReadOnlyArray>, + nameParts: ReadonlyArray, + properties: ReadonlyArray>, generateOptionalObjectProperties?: boolean = false, ): void { const structNameParts = nameParts; diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaPojo/PojoCollector.js b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaPojo/PojoCollector.js index 39bca081570..850f550d7fe 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaPojo/PojoCollector.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaPojo/PojoCollector.js @@ -29,7 +29,7 @@ const {capitalize} = require('../../Utils'); export type Pojo = { name: string, namespace: string, - properties: $ReadOnlyArray, + properties: ReadonlyArray, }; export type PojoProperty = NamedShape; @@ -63,12 +63,12 @@ export type PojoTypeAnnotation = | Readonly<{ type: 'StringEnumTypeAnnotation', default: string, - options: $ReadOnlyArray, + options: ReadonlyArray, }> | Readonly<{ type: 'Int32EnumTypeAnnotation', default: number, - options: $ReadOnlyArray, + options: ReadonlyArray, }> | ReservedPropTypeAnnotation | PojoTypeAliasAnnotation @@ -84,7 +84,7 @@ export type PojoTypeAnnotation = | Readonly<{ type: 'StringEnumTypeAnnotation', default: string, - options: $ReadOnlyArray, + options: ReadonlyArray, }> | PojoTypeAliasAnnotation | ReservedPropTypeAnnotation @@ -182,7 +182,7 @@ class PojoCollector { }); } - getAllPojos(): $ReadOnlyArray { + getAllPojos(): ReadonlyArray { return [...this._pojos.values()]; } } diff --git a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js index 3d538f7d4d0..0ad125f1d82 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js +++ b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js @@ -184,7 +184,7 @@ function normalizeInputEventName(name: string) { // Replicates the behavior of viewConfig in RCTComponentData.m function getValidAttributesForEvents( - events: $ReadOnlyArray, + events: ReadonlyArray, imports: Set, ) { imports.add( diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js index b92240bd9c7..dddf253913a 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js @@ -170,7 +170,7 @@ const ModuleSpecClassDeclarationTemplate = ({ enums: string, moduleEventEmitters: EventEmitterCpp[], moduleFunctions: string[], - methods: $ReadOnlyArray>, + methods: ReadonlyArray>, }>) => { return `${enums}${structs} template @@ -504,7 +504,7 @@ function getMemberValueAppearance(member: NativeModuleEnumMember['value']) { function generateEnum( hasteModuleName: string, origEnumName: string, - members: $ReadOnlyArray, + members: ReadonlyArray, memberType: NativeModuleEnumMemberType, ): string { const enumName = getEnumName(hasteModuleName, origEnumName); diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js index 65315adae2f..a1dc7860e02 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js @@ -60,8 +60,8 @@ const ModuleClassConstructorTemplate = ({ methods, }: Readonly<{ hasteModuleName: string, - eventEmitters: $ReadOnlyArray, - methods: $ReadOnlyArray<{ + eventEmitters: ReadonlyArray, + methods: ReadonlyArray<{ propertyName: string, argCount: number, }>, @@ -109,7 +109,7 @@ const FileTemplate = ({ libraryName: string, include: string, modules: string, - moduleLookups: $ReadOnlyArray<{ + moduleLookups: ReadonlyArray<{ hasteModuleName: string, moduleName: string, }>, @@ -527,7 +527,7 @@ module.exports = { }) .join('\n'); - const moduleLookups: $ReadOnlyArray<{ + const moduleLookups: ReadonlyArray<{ hasteModuleName: string, moduleName: string, }> = Object.keys(nativeModules) diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js index 036d4203d16..31df79ac202 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js @@ -47,13 +47,13 @@ type StructContext = 'CONSTANTS' | 'REGULAR'; export type RegularStruct = Readonly<{ context: 'REGULAR', name: string, - properties: $ReadOnlyArray, + properties: ReadonlyArray, }>; export type ConstantsStruct = Readonly<{ context: 'CONSTANTS', name: string, - properties: $ReadOnlyArray, + properties: ReadonlyArray, }>; export type Struct = RegularStruct | ConstantsStruct; @@ -240,7 +240,7 @@ class StructCollector { } } - getAllStructs(): $ReadOnlyArray { + getAllStructs(): ReadonlyArray { return [...this._structs.values()]; } diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js index 6abb2686960..ed6fda95bfa 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js @@ -57,7 +57,7 @@ export type MethodSerializationOutput = Readonly<{ methodName: string, protocolMethod: string, selector: string, - structParamRecords: $ReadOnlyArray, + structParamRecords: ReadonlyArray, returnJSType: ReturnJSType, argCount: number, }>; @@ -67,7 +67,7 @@ function serializeMethod( property: NativeModulePropertyShape, structCollector: StructCollector, resolveAlias: AliasResolver, -): $ReadOnlyArray { +): ReadonlyArray { const {name: methodName, typeAnnotation: nullableTypeAnnotation} = property; const [propertyTypeAnnotation] = unwrapNullable(nullableTypeAnnotation); const {params} = propertyTypeAnnotation; @@ -472,7 +472,7 @@ function serializeConstantsProtocolMethods( property: NativeModulePropertyShape, structCollector: StructCollector, resolveAlias: AliasResolver, -): $ReadOnlyArray { +): ReadonlyArray { const [propertyTypeAnnotation] = unwrapNullable(property.typeAnnotation); if (propertyTypeAnnotation.params.length !== 0) { throw new Error( diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js index bc24adee3ac..8898f329472 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js @@ -29,10 +29,10 @@ const ModuleTemplate = ({ methodSerializationOutputs, }: Readonly<{ hasteModuleName: string, - structs: $ReadOnlyArray, + structs: ReadonlyArray, moduleName: string, - eventEmitters: $ReadOnlyArray, - methodSerializationOutputs: $ReadOnlyArray, + eventEmitters: ReadonlyArray, + methodSerializationOutputs: ReadonlyArray, }>) => ` @implementation ${hasteModuleName}SpecBase ${eventEmitters @@ -129,7 +129,7 @@ const MethodMapEntryTemplate = ({ }: Readonly<{ hasteModuleName: string, methodName: string, - structParamRecords: $ReadOnlyArray, + structParamRecords: ReadonlyArray, argCount: number, }>) => ` methodMap_["${methodName}"] = MethodMetadata {${argCount}, __hostFunction_${hasteModuleName}SpecJSI_${methodName}}; @@ -141,10 +141,10 @@ const MethodMapEntryTemplate = ({ function serializeModuleSource( hasteModuleName: string, - structs: $ReadOnlyArray, + structs: ReadonlyArray, moduleName: string, - eventEmitters: $ReadOnlyArray, - methodSerializationOutputs: $ReadOnlyArray, + eventEmitters: ReadonlyArray, + methodSerializationOutputs: ReadonlyArray, ): string { return ModuleTemplate({ hasteModuleName, diff --git a/packages/react-native-codegen/src/parsers/__tests__/error-utils-test.js b/packages/react-native-codegen/src/parsers/__tests__/error-utils-test.js index b253408ace3..5feec430b06 100644 --- a/packages/react-native-codegen/src/parsers/__tests__/error-utils-test.js +++ b/packages/react-native-codegen/src/parsers/__tests__/error-utils-test.js @@ -635,7 +635,7 @@ describe('throwIfModuleTypeIsUnsupported', () => { describe('throwIfMoreThanOneModuleInterfaceParserError', () => { it("don't throw error if module specs length is <= 1", () => { const nativeModuleName = 'moduleName'; - const moduleSpecs: $ReadOnlyArray<$FlowFixMe> = []; + const moduleSpecs: ReadonlyArray<$FlowFixMe> = []; const parserType = 'Flow'; expect(() => { diff --git a/packages/react-native-codegen/src/parsers/error-utils.js b/packages/react-native-codegen/src/parsers/error-utils.js index f7b8c502b6a..0ebf2aa9ecf 100644 --- a/packages/react-native-codegen/src/parsers/error-utils.js +++ b/packages/react-native-codegen/src/parsers/error-utils.js @@ -239,7 +239,7 @@ function throwIfPropertyValueTypeIsUnsupported( function throwIfMoreThanOneModuleInterfaceParserError( nativeModuleName: string, - moduleSpecs: $ReadOnlyArray<$FlowFixMe>, + moduleSpecs: ReadonlyArray<$FlowFixMe>, parserType: ParserType, ) { if (moduleSpecs.length > 1) { @@ -333,7 +333,7 @@ function throwIfPartialWithMoreParameter(typeAnnotation: $FlowFixMe) { } function throwIfMoreThanOneCodegenNativecommands( - commandsTypeNames: $ReadOnlyArray<$FlowFixMe>, + commandsTypeNames: ReadonlyArray<$FlowFixMe>, ) { if (commandsTypeNames.length > 1) { throw new Error('codegenNativeCommands may only be called once in a file'); @@ -375,9 +375,9 @@ function throwIfBubblingTypeIsNull( } function throwIfArgumentPropsAreNull( - argumentProps: ?$ReadOnlyArray<$FlowFixMe>, + argumentProps: ?ReadonlyArray<$FlowFixMe>, eventName: string, -): $ReadOnlyArray<$FlowFixMe> { +): ReadonlyArray<$FlowFixMe> { if (!argumentProps) { throw new Error(`Unable to determine event arguments for "${eventName}"`); } diff --git a/packages/react-native-codegen/src/parsers/errors.js b/packages/react-native-codegen/src/parsers/errors.js index ba5b3604efb..9ae9e983a57 100644 --- a/packages/react-native-codegen/src/parsers/errors.js +++ b/packages/react-native-codegen/src/parsers/errors.js @@ -15,7 +15,7 @@ import type {Parser} from './parser'; export type ParserType = 'Flow' | 'TypeScript'; class ParserError extends Error { - nodes: $ReadOnlyArray<$FlowFixMe>; + nodes: ReadonlyArray<$FlowFixMe>; constructor( nativeModuleName: string, astNodeOrNodes: $FlowFixMe, @@ -57,8 +57,8 @@ class ModuleInterfaceNotFoundParserError extends ParserError { class MoreThanOneModuleInterfaceParserError extends ParserError { constructor( nativeModuleName: string, - flowModuleInterfaces: $ReadOnlyArray<$FlowFixMe>, - names: $ReadOnlyArray, + flowModuleInterfaces: ReadonlyArray<$FlowFixMe>, + names: ReadonlyArray, language: ParserType, ) { const finalName = names[names.length - 1]; diff --git a/packages/react-native-codegen/src/parsers/flow/components/commands.js b/packages/react-native-codegen/src/parsers/flow/components/commands.js index 72468977218..7874ab8534a 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/commands.js +++ b/packages/react-native-codegen/src/parsers/flow/components/commands.js @@ -33,7 +33,7 @@ function buildCommandSchema( optional: boolean, typeAnnotation: { type: 'FunctionTypeAnnotation', - params: $ReadOnlyArray<{ + params: ReadonlyArray<{ name: string, optional: boolean, typeAnnotation: CommandParamTypeAnnotation, @@ -224,10 +224,10 @@ function getCommandArrayElementTypeType( } function getCommands( - commandTypeAST: $ReadOnlyArray, + commandTypeAST: ReadonlyArray, types: TypeDeclarationMap, parser: Parser, -): $ReadOnlyArray> { +): ReadonlyArray> { return commandTypeAST .filter(property => property.type === 'ObjectTypeProperty') .map(property => buildCommandSchema(property, types, parser)) diff --git a/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js b/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js index c8f2d46ec2f..b3d57458beb 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js +++ b/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js @@ -187,10 +187,10 @@ function getTypeAnnotationForArray<+T>( } function flattenProperties( - typeDefinition: $ReadOnlyArray, + typeDefinition: ReadonlyArray, types: TypeDeclarationMap, parser: Parser, -): $ReadOnlyArray { +): ReadonlyArray { return typeDefinition .map(property => { if (property.type === 'ObjectTypeProperty') { diff --git a/packages/react-native-codegen/src/parsers/flow/components/events.js b/packages/react-native-codegen/src/parsers/flow/components/events.js index 7f241cd0af6..1c6d05fe282 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/events.js +++ b/packages/react-native-codegen/src/parsers/flow/components/events.js @@ -275,10 +275,10 @@ type TypeMap = { }; function getEvents( - eventTypeAST: $ReadOnlyArray, + eventTypeAST: ReadonlyArray, types: TypeMap, parser: Parser, -): $ReadOnlyArray { +): ReadonlyArray { return eventTypeAST .filter(property => property.type === 'ObjectTypeProperty') .map(property => buildEventSchema(types, property, parser)) diff --git a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js index 952d65b300c..512fa8e84d9 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js @@ -35,7 +35,7 @@ type PrimitiveTypeAnnotationType = | 'FloatTypeAnnotation' | 'BooleanTypeAnnotation'; -const PRIMITIVES: $ReadOnlyArray<[string, PrimitiveTypeAnnotationType]> = [ +const PRIMITIVES: ReadonlyArray<[string, PrimitiveTypeAnnotationType]> = [ ['string', 'StringTypeAnnotation'], ['number', 'NumberTypeAnnotation'], ['Int32', 'Int32TypeAnnotation'], @@ -44,9 +44,7 @@ const PRIMITIVES: $ReadOnlyArray<[string, PrimitiveTypeAnnotationType]> = [ ['boolean', 'BooleanTypeAnnotation'], ]; -const RESERVED_FUNCTION_VALUE_TYPE_NAME: $ReadOnlyArray<'RootTag'> = [ - 'RootTag', -]; +const RESERVED_FUNCTION_VALUE_TYPE_NAME: ReadonlyArray<'RootTag'> = ['RootTag']; const MODULE_NAME = 'NativeFoo'; diff --git a/packages/react-native-codegen/src/parsers/flow/parser.js b/packages/react-native-codegen/src/parsers/flow/parser.js index d251d7976db..ac2c351c9ad 100644 --- a/packages/react-native-codegen/src/parsers/flow/parser.js +++ b/packages/react-native-codegen/src/parsers/flow/parser.js @@ -152,7 +152,7 @@ class FlowParser implements Parser { getFunctionTypeAnnotationParameters( functionTypeAnnotation: $FlowFixMe, - ): $ReadOnlyArray<$FlowFixMe> { + ): ReadonlyArray<$FlowFixMe> { return functionTypeAnnotation.params; } @@ -227,7 +227,7 @@ class FlowParser implements Parser { parseEnumMembers( typeAnnotation: $FlowFixMe, - ): $ReadOnlyArray { + ): ReadonlyArray { return typeAnnotation.members.map(member => { const value = typeof member.init?.value === 'number' @@ -371,7 +371,7 @@ class FlowParser implements Parser { return annotatedElement.right.properties; } - bodyProperties(typeAlias: $FlowFixMe): $ReadOnlyArray<$FlowFixMe> { + bodyProperties(typeAlias: $FlowFixMe): ReadonlyArray<$FlowFixMe> { return typeAlias.body.properties; } @@ -489,9 +489,9 @@ class FlowParser implements Parser { } removeKnownExtends( - typeDefinition: $ReadOnlyArray, + typeDefinition: ReadonlyArray, types: TypeDeclarationMap, - ): $ReadOnlyArray { + ): ReadonlyArray { return typeDefinition.filter( prop => prop.type !== 'ObjectTypeSpreadProperty' || @@ -500,9 +500,9 @@ class FlowParser implements Parser { } getExtendsProps( - typeDefinition: $ReadOnlyArray, + typeDefinition: ReadonlyArray, types: TypeDeclarationMap, - ): $ReadOnlyArray { + ): ReadonlyArray { return typeDefinition .filter(prop => prop.type === 'ObjectTypeSpreadProperty') .map(prop => this.extendsForProp(prop, types, this)) @@ -510,11 +510,11 @@ class FlowParser implements Parser { } getProps( - typeDefinition: $ReadOnlyArray, + typeDefinition: ReadonlyArray, types: TypeDeclarationMap, ): { - props: $ReadOnlyArray>, - extendsProps: $ReadOnlyArray, + props: ReadonlyArray>, + extendsProps: ReadonlyArray, } { const nonExtendsProps = this.removeKnownExtends(typeDefinition, types); const props = flattenProperties(nonExtendsProps, types, this) diff --git a/packages/react-native-codegen/src/parsers/parser.js b/packages/react-native-codegen/src/parsers/parser.js index 4e25ed6495c..a7e10d8ea9b 100644 --- a/packages/react-native-codegen/src/parsers/parser.js +++ b/packages/react-native-codegen/src/parsers/parser.js @@ -183,7 +183,7 @@ export interface Parser { */ getFunctionTypeAnnotationParameters( functionTypeAnnotation: $FlowFixMe, - ): $ReadOnlyArray<$FlowFixMe>; + ): ReadonlyArray<$FlowFixMe>; /** * Given a parameter, it returns the function name of the parameter. @@ -235,7 +235,7 @@ export interface Parser { */ parseEnumMembers( typeAnnotation: $FlowFixMe, - ): $ReadOnlyArray; + ): ReadonlyArray; /** * Given a node, it returns true if it is a module interface @@ -328,7 +328,7 @@ export interface Parser { * @parameter typeAlias: the type alias. * @returns: an array of properties. */ - bodyProperties(typeAlias: $FlowFixMe): $ReadOnlyArray<$FlowFixMe>; + bodyProperties(typeAlias: $FlowFixMe): ReadonlyArray<$FlowFixMe>; /** * Given a keyword convert it to TypeAnnotation. @@ -382,11 +382,11 @@ export interface Parser { getResolveTypeAnnotationFN(): ResolveTypeAnnotationFN; getProps( - typeDefinition: $ReadOnlyArray, + typeDefinition: ReadonlyArray, types: TypeDeclarationMap, ): { - props: $ReadOnlyArray>, - extendsProps: $ReadOnlyArray, + props: ReadonlyArray>, + extendsProps: ReadonlyArray, }; getProperties(typeName: string, types: TypeDeclarationMap): $FlowFixMe; diff --git a/packages/react-native-codegen/src/parsers/parserMock.js b/packages/react-native-codegen/src/parsers/parserMock.js index 5ce04ca1139..825b802e1b4 100644 --- a/packages/react-native-codegen/src/parsers/parserMock.js +++ b/packages/react-native-codegen/src/parsers/parserMock.js @@ -133,7 +133,7 @@ export class MockedParser implements Parser { getFunctionTypeAnnotationParameters( functionTypeAnnotation: $FlowFixMe, - ): $ReadOnlyArray<$FlowFixMe> { + ): ReadonlyArray<$FlowFixMe> { return functionTypeAnnotation.params; } @@ -170,7 +170,7 @@ export class MockedParser implements Parser { parseEnumMembers( typeAnnotation: $FlowFixMe, - ): $ReadOnlyArray { + ): ReadonlyArray { return typeAnnotation.type === 'StringTypeAnnotation' ? [ { @@ -279,7 +279,7 @@ export class MockedParser implements Parser { return annotatedElement.right.properties; } - bodyProperties(typeAlias: $FlowFixMe): $ReadOnlyArray<$FlowFixMe> { + bodyProperties(typeAlias: $FlowFixMe): ReadonlyArray<$FlowFixMe> { return typeAlias.body.properties; } @@ -401,9 +401,9 @@ export class MockedParser implements Parser { } getExtendsProps( - typeDefinition: $ReadOnlyArray, + typeDefinition: ReadonlyArray, types: TypeDeclarationMap, - ): $ReadOnlyArray { + ): ReadonlyArray { return typeDefinition .filter(prop => prop.type === 'ObjectTypeSpreadProperty') .map(prop => this.extendsForProp(prop, types, this)) @@ -439,9 +439,9 @@ export class MockedParser implements Parser { } removeKnownExtends( - typeDefinition: $ReadOnlyArray, + typeDefinition: ReadonlyArray, types: TypeDeclarationMap, - ): $ReadOnlyArray { + ): ReadonlyArray { return typeDefinition.filter( prop => prop.type !== 'ObjectTypeSpreadProperty' || @@ -450,11 +450,11 @@ export class MockedParser implements Parser { } getProps( - typeDefinition: $ReadOnlyArray, + typeDefinition: ReadonlyArray, types: TypeDeclarationMap, ): { - props: $ReadOnlyArray>, - extendsProps: $ReadOnlyArray, + props: ReadonlyArray>, + extendsProps: ReadonlyArray, } { const nonExtendsProps = this.removeKnownExtends(typeDefinition, types); const props = flattenProperties(nonExtendsProps, types, this) diff --git a/packages/react-native-codegen/src/parsers/parsers-commons.js b/packages/react-native-codegen/src/parsers/parsers-commons.js index 1d4f2cf4257..50c2d73ec6b 100644 --- a/packages/react-native-codegen/src/parsers/parsers-commons.js +++ b/packages/react-native-codegen/src/parsers/parsers-commons.js @@ -78,7 +78,7 @@ const { const invariant = require('invariant'); export type CommandOptions = Readonly<{ - supportedCommands: $ReadOnlyArray, + supportedCommands: ReadonlyArray, }>; // $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser @@ -90,7 +90,7 @@ type ExtendedPropResult = { } | null; export type EventArgumentReturnType = { - argumentProps: ?$ReadOnlyArray<$FlowFixMe>, + argumentProps: ?ReadonlyArray<$FlowFixMe>, paperTopLevelNameDeprecated: ?$FlowFixMe, bubblingType: ?'direct' | 'bubble', }; @@ -751,7 +751,7 @@ const buildModuleSchema = ( ): NativeModuleSchema => { const language = parser.language(); const types = parser.getTypes(ast); - const moduleSpecs = (Object.values(types): $ReadOnlyArray<$FlowFixMe>).filter( + const moduleSpecs = (Object.values(types): ReadonlyArray<$FlowFixMe>).filter( t => parser.isModuleInterface(t), ); @@ -793,7 +793,7 @@ const buildModuleSchema = ( parser, ) : {}; - const properties: $ReadOnlyArray<$FlowFixMe> = + const properties: ReadonlyArray<$FlowFixMe> = language === 'Flow' ? moduleSpec.body.properties : moduleSpec.body.body; type PropertyShape = @@ -1043,8 +1043,8 @@ function getCommandTypeNameAndOptionsExpression( } function propertyNames( - properties: $ReadOnlyArray<$FlowFixMe>, -): $ReadOnlyArray<$FlowFixMe> { + properties: ReadonlyArray<$FlowFixMe>, +): ReadonlyArray<$FlowFixMe> { return properties .map(property => property && property.key && property.key.name) .filter(Boolean); @@ -1293,7 +1293,7 @@ function buildPropertiesForEvent( } function verifyPropNotAlreadyDefined( - props: $ReadOnlyArray, + props: ReadonlyArray, needleProp: PropAST, ) { const propName = needleProp.key.name;