From a3660a273a93177502ad9360241079aab049d726 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Wed, 14 Oct 2026 15:59:26 -0700 Subject: [PATCH] Replace `Object`/`Function` annotations with `any` Summary: With `experimental.function_and_object_type_is_no_longer_any`, Flow resolves `Object` and `Function` to the builtin class types instead of `any`. Changelog: [Internal] Differential Revision: D125312021 --- .../src/parsers/flow/components/commands.js | 2 +- .../src/parsers/flow/components/events.js | 4 ++-- .../react-native-codegen/src/parsers/parsers-commons.js | 2 +- .../src/parsers/typescript/components/commands.js | 2 +- .../src/parsers/typescript/components/events.js | 2 +- .../src/parsers/typescript/components/extends.js | 2 +- packages/react-native/Libraries/Animated/AnimatedEvent.js | 2 +- .../Libraries/Animated/AnimatedImplementation.js | 4 ++-- .../react-native/Libraries/Animated/nodes/AnimatedNode.js | 2 +- .../Libraries/Animated/nodes/AnimatedProps.js | 4 ++-- .../Libraries/Animated/nodes/AnimatedTransform.js | 2 +- packages/react-native/Libraries/Core/ExceptionsManager.js | 2 +- .../Libraries/PushNotificationIOS/PushNotificationIOS.js | 3 +-- packages/react-native/scripts/spm/spm-utils.js | 2 +- .../src/private/animated/NativeAnimatedHelper.js | 2 +- packages/rn-tester/IntegrationTests/AppEventsTest.js | 2 +- packages/rn-tester/js/components/ListExampleShared.js | 2 +- packages/rn-tester/js/components/RNTesterExampleFilter.js | 4 ++-- .../js/examples/AnimatedGratuitousApp/AnExApp.js | 2 +- .../js/examples/AnimatedGratuitousApp/AnExBobble.js | 2 +- .../PlatformTest/RNTesterPlatformTestEventRecorder.js | 2 +- .../OrientationChange/OrientationChangeExample.js | 2 +- packages/rn-tester/js/examples/RTL/RTLExample.js | 6 +++--- .../js/examples/SectionList/SectionList-scrollable.js | 2 +- packages/rn-tester/js/examples/XHR/XHRExampleDownload.js | 4 ++-- packages/rn-tester/js/examples/XHR/XHRExampleFetch.js | 2 +- packages/virtualized-lists/Lists/VirtualizedList.js | 8 ++++---- packages/virtualized-lists/Lists/VirtualizedListProps.js | 2 +- .../virtualized-lists/Lists/VirtualizedSectionList.js | 4 ++-- 29 files changed, 40 insertions(+), 41 deletions(-) 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 381fef3c88dd..de495e00d1bf 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/commands.js +++ b/packages/react-native-codegen/src/parsers/flow/components/commands.js @@ -22,7 +22,7 @@ import type {TypeDeclarationMap} from '../../utils'; const {getValueFromTypes} = require('../utils.js'); // $FlowFixMe[unclear-type] there's no flowtype for ASTs -type EventTypeAST = Object; +type EventTypeAST = any; function buildCommandSchema( property: EventTypeAST, 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 1c6d05fe282c..e84df19c2cc8 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/events.js +++ b/packages/react-native-codegen/src/parsers/flow/components/events.js @@ -266,11 +266,11 @@ function buildEventSchema( } // $FlowFixMe[unclear-type] there's no flowtype for ASTs -type EventTypeAST = Object; +type EventTypeAST = any; type TypeMap = { // $FlowFixMe[unclear-type] there's no flowtype for ASTs - [string]: Object, + [string]: any, ... }; diff --git a/packages/react-native-codegen/src/parsers/parsers-commons.js b/packages/react-native-codegen/src/parsers/parsers-commons.js index a8b64de42408..08be2699c869 100644 --- a/packages/react-native-codegen/src/parsers/parsers-commons.js +++ b/packages/react-native-codegen/src/parsers/parsers-commons.js @@ -83,7 +83,7 @@ export type CommandOptions = Readonly<{ }>; // $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser -type OptionsAST = Object; +type OptionsAST = any; type ExtendedPropResult = { type: 'ReactNativeBuiltInType', diff --git a/packages/react-native-codegen/src/parsers/typescript/components/commands.js b/packages/react-native-codegen/src/parsers/typescript/components/commands.js index f097b2b9314b..71ebac6eaa36 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/commands.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/commands.js @@ -23,7 +23,7 @@ const {parseTopLevelType} = require('../parseTopLevelType'); const {getPrimitiveTypeAnnotation} = require('./componentsUtils'); // $FlowFixMe[unclear-type] there's no flowtype for ASTs -type EventTypeAST = Object; +type EventTypeAST = any; function buildCommandSchemaInternal( name: string, diff --git a/packages/react-native-codegen/src/parsers/typescript/components/events.js b/packages/react-native-codegen/src/parsers/typescript/components/events.js index faa4bc11c0ae..05015df3aa07 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/events.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/events.js @@ -238,7 +238,7 @@ function findEventArgumentsAndType( } // $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser -type EventTypeAST = Object; +type EventTypeAST = any; function buildEventSchema( types: TypeDeclarationMap, diff --git a/packages/react-native-codegen/src/parsers/typescript/components/extends.js b/packages/react-native-codegen/src/parsers/typescript/components/extends.js index 571408f01293..6be0e3b774a4 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/extends.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/extends.js @@ -24,7 +24,7 @@ function isEvent(typeAnnotation: $FlowFixMe, parser: Parser): boolean { } // $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser -type PropsAST = Object; +type PropsAST = any; function categorizeProps( typeDefinition: ReadonlyArray, diff --git a/packages/react-native/Libraries/Animated/AnimatedEvent.js b/packages/react-native/Libraries/Animated/AnimatedEvent.js index cbc0e3b38895..2393a5c41012 100644 --- a/packages/react-native/Libraries/Animated/AnimatedEvent.js +++ b/packages/react-native/Libraries/Animated/AnimatedEvent.js @@ -156,7 +156,7 @@ function validateMapping(argMapping: ReadonlyArray, args: any) { export class AnimatedEvent { _argMapping: ReadonlyArray; // $FlowFixMe[unclear-type] - _listeners: Array = []; + _listeners: Array = []; _attachedEvent: ?{detach: () => void, ...}; __isNative: boolean; __platformConfig: ?PlatformConfig; diff --git a/packages/react-native/Libraries/Animated/AnimatedImplementation.js b/packages/react-native/Libraries/Animated/AnimatedImplementation.js index 4ff1bb86c83f..14cbef1fb195 100644 --- a/packages/react-native/Libraries/Animated/AnimatedImplementation.js +++ b/packages/react-native/Libraries/Animated/AnimatedImplementation.js @@ -128,9 +128,9 @@ const _combineCallbacks = function ( const maybeVectorAnim = function ( value: AnimatedValue | AnimatedValueXY | AnimatedColor, // $FlowFixMe[unclear-type] - config: Object, + config: any, // $FlowFixMe[unclear-type] - anim: (value: AnimatedValue, config: Object) => CompositeAnimation, + anim: (value: AnimatedValue, config: any) => CompositeAnimation, ): ?CompositeAnimation { if (value instanceof AnimatedValueXY) { const configX = {...config}; diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js b/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js index b0b0179c5331..99984d248636 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js @@ -228,7 +228,7 @@ export default class AnimatedNode { } // $FlowFixMe[unclear-type] - __getNativeConfig(): Object { + __getNativeConfig(): any { throw new Error( 'This JS animated node type cannot be used as native animated node', ); diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js b/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js index 8ea0aeae98fc..c2bf27ee46f9 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js @@ -120,7 +120,7 @@ export default class AnimatedProps extends AnimatedNode { } // $FlowFixMe[unclear-type] - __getValue(): Object { + __getValue(): any { const props: {[string]: unknown} = {}; const keys = Object.keys(this._props); @@ -146,7 +146,7 @@ export default class AnimatedProps extends AnimatedNode { * created by this `AnimatedProps` instance. */ // $FlowFixMe[unclear-type] - __getValueWithStaticProps(staticProps: Object): Object { + __getValueWithStaticProps(staticProps: any): any { const props: {[string]: unknown} = {...staticProps}; const keys = Object.keys(staticProps); diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedTransform.js b/packages/react-native/Libraries/Animated/nodes/AnimatedTransform.js index 46d9ae1f5657..8ea5cf05d0dd 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedTransform.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedTransform.js @@ -96,7 +96,7 @@ export default class AnimatedTransform extends AnimatedWithChildren { __getValueWithStaticTransforms( // $FlowFixMe[unclear-type] - staticTransforms: ReadonlyArray, + staticTransforms: ReadonlyArray, // $FlowFixMe[unclear-type] ): ReadonlyArray { const values = []; diff --git a/packages/react-native/Libraries/Core/ExceptionsManager.js b/packages/react-native/Libraries/Core/ExceptionsManager.js index e7eafc04930a..6c9a11aa6e25 100644 --- a/packages/react-native/Libraries/Core/ExceptionsManager.js +++ b/packages/react-native/Libraries/Core/ExceptionsManager.js @@ -77,7 +77,7 @@ function reportException( } // $FlowFixMe[unclear-type] - const extraData: Object = { + const extraData: any = { // $FlowFixMe[incompatible-use] we can't define a type with a Symbol-keyed field in flow ...e[decoratedExtraDataKey], jsEngine: e.jsEngine, diff --git a/packages/react-native/Libraries/PushNotificationIOS/PushNotificationIOS.js b/packages/react-native/Libraries/PushNotificationIOS/PushNotificationIOS.js index 956100a7d777..1c69fc55d83b 100644 --- a/packages/react-native/Libraries/PushNotificationIOS/PushNotificationIOS.js +++ b/packages/react-native/Libraries/PushNotificationIOS/PushNotificationIOS.js @@ -279,8 +279,7 @@ class PushNotificationIOS { * See https://reactnative.dev/docs/pushnotificationios#getdeliverednotifications */ static getDeliveredNotifications( - // $FlowFixMe[unclear-type] - callback: (notifications: Array) => void, + callback: (notifications: Array) => void, ): void { invariant( NativePushNotificationManagerIOS, diff --git a/packages/react-native/scripts/spm/spm-utils.js b/packages/react-native/scripts/spm/spm-utils.js index fc5313623e71..a2979b375a04 100644 --- a/packages/react-native/scripts/spm/spm-utils.js +++ b/packages/react-native/scripts/spm/spm-utils.js @@ -214,7 +214,7 @@ function deriveAppName( } // $FlowFixMe[unclear-type] JSON data has dynamic shape -function readPackageJson(dir /*: string */) /*: Object | null */ { +function readPackageJson(dir /*: string */) /*: any | null */ { const pkgPath = path.join(dir, 'package.json'); if (!fs.existsSync(pkgPath)) { return null; diff --git a/packages/react-native/src/private/animated/NativeAnimatedHelper.js b/packages/react-native/src/private/animated/NativeAnimatedHelper.js index da9fb941aebb..d455c7e240a5 100644 --- a/packages/react-native/src/private/animated/NativeAnimatedHelper.js +++ b/packages/react-native/src/private/animated/NativeAnimatedHelper.js @@ -35,7 +35,7 @@ interface NativeAnimatedModuleSpec extends NativeAnimatedTurboModuleSpec { readonly connectAnimatedNodeToShadowNodeFamily?: ( nodeTag: number, // $FlowExpectedError[unclear-type]. - shadowNode: Object, + shadowNode: any, ) => void; } diff --git a/packages/rn-tester/IntegrationTests/AppEventsTest.js b/packages/rn-tester/IntegrationTests/AppEventsTest.js index eaca56f5f97b..61cae363bff0 100644 --- a/packages/rn-tester/IntegrationTests/AppEventsTest.js +++ b/packages/rn-tester/IntegrationTests/AppEventsTest.js @@ -26,7 +26,7 @@ const {TestModule} = NativeModules; const TEST_PAYLOAD = {foo: 'bar'}; type AppEvent = { - data: Object, + data: any, ts: number, }; diff --git a/packages/rn-tester/js/components/ListExampleShared.js b/packages/rn-tester/js/components/ListExampleShared.js index e1cf4dad65cc..cad9d6e62e2b 100644 --- a/packages/rn-tester/js/components/ListExampleShared.js +++ b/packages/rn-tester/js/components/ListExampleShared.js @@ -276,7 +276,7 @@ function renderSmallSwitchOption( ); } -function PlainInput(props: Object): React.Node { +function PlainInput(props: any): React.Node { return ( = { - filter: Function, - render: Function, + filter: any, + render: any, disableSearch?: boolean, testID?: string, hideFilterPills?: boolean, diff --git a/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExApp.js b/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExApp.js index dbc5a7dc514f..b4f9fdad752b 100644 --- a/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExApp.js +++ b/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExApp.js @@ -121,7 +121,7 @@ class Circle extends React.Component { }, }; } - const animatedStyle: Object = { + const animatedStyle: any = { shadowOpacity: this.state.pop, // no need for interpolation (step2d: uncomment) transform: [ { diff --git a/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExBobble.js b/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExBobble.js index 97e0a076a9e2..4fdab7b38614 100644 --- a/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExBobble.js +++ b/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExBobble.js @@ -138,7 +138,7 @@ const styles = StyleSheet.create({ }, }); -function computeNewSelected(gestureState: Object): ?number { +function computeNewSelected(gestureState: any): ?number { const {dx, dy} = gestureState; let minDist = Infinity; let newSelected = null; diff --git a/packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestEventRecorder.js b/packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestEventRecorder.js index 4c71347d85b3..8ece7eb1338d 100644 --- a/packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestEventRecorder.js +++ b/packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestEventRecorder.js @@ -172,7 +172,7 @@ export default class RNTesterPlatformTestEventRecorder { export function useRecorderTestEventHandlers( eventRecorder: RNTesterPlatformTestEventRecorder, targetNames: ReadonlyArray, - callback?: (event: Object, eventType: string, targetName: string) => void, + callback?: (event: any, eventType: string, targetName: string) => void, ): Readonly<{[targetName: string]: ViewProps}> { return useMemo( () => eventRecorder.createRecorderTestEventHandlers(targetNames, callback), diff --git a/packages/rn-tester/js/examples/OrientationChange/OrientationChangeExample.js b/packages/rn-tester/js/examples/OrientationChange/OrientationChangeExample.js index db4aea18a175..83fc8eb257b3 100644 --- a/packages/rn-tester/js/examples/OrientationChange/OrientationChangeExample.js +++ b/packages/rn-tester/js/examples/OrientationChange/OrientationChangeExample.js @@ -23,7 +23,7 @@ const OrientationChangeExample = (): React.Node => { }); useEffect(() => { - const onOrientationChange = (orientation: Object) => { + const onOrientationChange = (orientation: any) => { setState({ currentOrientation: orientation.name, orientationDegrees: orientation.rotationDegrees, diff --git a/packages/rn-tester/js/examples/RTL/RTLExample.js b/packages/rn-tester/js/examples/RTL/RTLExample.js index c8fa0a915a11..432ce5d892be 100644 --- a/packages/rn-tester/js/examples/RTL/RTLExample.js +++ b/packages/rn-tester/js/examples/RTL/RTLExample.js @@ -34,7 +34,7 @@ type RTLToggleState = {isRTL: boolean, ...}; type AnimationState = { toggleStatus: any, - linear: Object, + linear: any, windowWidth: number, ... }; @@ -297,13 +297,13 @@ class AnimationExample extends React.Component { ); } - _onLayout = (e: Object) => { + _onLayout = (e: any) => { this.setState({ windowWidth: e.nativeEvent.layout.width, }); }; - _linearTap = (e: Object) => { + _linearTap = (e: any) => { this.setState({ toggleStatus: { ...this.state.toggleStatus, diff --git a/packages/rn-tester/js/examples/SectionList/SectionList-scrollable.js b/packages/rn-tester/js/examples/SectionList/SectionList-scrollable.js index e9db925ecf71..203e6fb5811a 100644 --- a/packages/rn-tester/js/examples/SectionList/SectionList-scrollable.js +++ b/packages/rn-tester/js/examples/SectionList/SectionList-scrollable.js @@ -235,7 +235,7 @@ export component SectionList_scrollable() { if (logViewable) { console.log( 'onViewableItemsChanged: ', - info.changed.map((v: Object) => ({ + info.changed.map((v: any) => ({ ...v, item: '...', section: v.section.key, diff --git a/packages/rn-tester/js/examples/XHR/XHRExampleDownload.js b/packages/rn-tester/js/examples/XHR/XHRExampleDownload.js index b079d5fea01c..bf8c6b5e717c 100644 --- a/packages/rn-tester/js/examples/XHR/XHRExampleDownload.js +++ b/packages/rn-tester/js/examples/XHR/XHRExampleDownload.js @@ -29,8 +29,8 @@ function roundKilo(value: number): number { return Math.round(value / 1000); } -class XHRExampleDownload extends React.Component<{...}, Object> { - state: Object = { +class XHRExampleDownload extends React.Component<{...}, any> { + state: any = { downloading: false, // set by onreadystatechange contentLength: 1, diff --git a/packages/rn-tester/js/examples/XHR/XHRExampleFetch.js b/packages/rn-tester/js/examples/XHR/XHRExampleFetch.js index 3550897bd128..b5e9fdee9933 100644 --- a/packages/rn-tester/js/examples/XHR/XHRExampleFetch.js +++ b/packages/rn-tester/js/examples/XHR/XHRExampleFetch.js @@ -23,7 +23,7 @@ import { class XHRExampleFetch extends React.Component { responseURL: ?string; - responseHeaders: ?Object; + responseHeaders: ?any; intervalId: ?ReturnType; constructor(props: any) { diff --git a/packages/virtualized-lists/Lists/VirtualizedList.js b/packages/virtualized-lists/Lists/VirtualizedList.js index 9d4616f55a96..cea36dfff968 100644 --- a/packages/virtualized-lists/Lists/VirtualizedList.js +++ b/packages/virtualized-lists/Lists/VirtualizedList.js @@ -348,7 +348,7 @@ class VirtualizedList extends StateSafePureComponent< } } - setNativeProps(props: Object) { + setNativeProps(props: LegacyObject) { if (this._scrollRef) { this._scrollRef.setNativeProps(props); } @@ -929,7 +929,7 @@ class VirtualizedList extends StateSafePureComponent< } _pushCells( - cells: Array, + cells: Array, stickyHeaderIndices: Array, stickyIndicesFromProps: ?Set, first: number, @@ -1015,7 +1015,7 @@ class VirtualizedList extends StateSafePureComponent< }; } - _onUpdateSeparators = (keys: Array, newProps: Object) => { + _onUpdateSeparators = (keys: Array, newProps: any) => { keys.forEach(key => { const ref = key != null && this._cellRefs[key]; ref && ref.updateSeparatorProps(newProps); @@ -1939,7 +1939,7 @@ class VirtualizedList extends StateSafePureComponent< this._onScroll(e); } - _onScroll = (e: Object) => { + _onScroll = (e: any) => { this._nestedChildLists.forEach(childList => { childList._onScroll(e); }); diff --git a/packages/virtualized-lists/Lists/VirtualizedListProps.js b/packages/virtualized-lists/Lists/VirtualizedListProps.js index f5675959f853..8e1f2cafc849 100644 --- a/packages/virtualized-lists/Lists/VirtualizedListProps.js +++ b/packages/virtualized-lists/Lists/VirtualizedListProps.js @@ -28,7 +28,7 @@ export type Item = any; export type Separators = { highlight: () => void, unhighlight: () => void, - updateProps: (select: 'leading' | 'trailing', newProps: Object) => void, + updateProps: (select: 'leading' | 'trailing', newProps: LegacyObject) => void, ... }; diff --git a/packages/virtualized-lists/Lists/VirtualizedSectionList.js b/packages/virtualized-lists/Lists/VirtualizedSectionList.js index f2d257d377d0..41bfc0c8888e 100644 --- a/packages/virtualized-lists/Lists/VirtualizedSectionList.js +++ b/packages/virtualized-lists/Lists/VirtualizedSectionList.js @@ -446,7 +446,7 @@ class VirtualizedSectionList< _getSeparatorComponent( index: number, - info?: ?Object, + info?: ?any, listItemCount: number, ): ?(React.ComponentType | React.MixedElement) { info = info || this._subExtractor(index); @@ -502,7 +502,7 @@ type ItemWithSeparatorProps = Readonly<{ prevCellKey?: ?string, updateHighlightFor: (prevCellKey: string, value: boolean) => void, updatePropsFor: (prevCellKey: string, value: Object) => void, - renderItem: Function, + renderItem: any, inverted: boolean, }>;