From 7884f6cfecf97811f804af619858556b072b5a9e Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Wed, 19 Oct 2022 10:25:09 -0700 Subject: [PATCH] Implicit instantiation codemod Summary: This diff adds explicit type arguments to polymorphic function calls that do not constrain their types. This codemod will reduce the error burden that will come in a future version of flow. This specific diff was generated by running: ``` flow codemod annotate-implicit-instantiations --write . flow --json --pretty | jq '.errors | .[] | .message | .[] | .loc |.source' | sort | uniq | sed -e 's/"//g' | xargs hg revert hg st -n | xargs grep "generated" | sed -e 's/:.*//g' | xargs hg revert arc f ``` So these are the codemod results that introduced no new errors and no generated files. Changelog: [Internal] drop-conflicts Reviewed By: SamChou19815 Differential Revision: D40413074 fbshipit-source-id: 42b52719978f1098169662b503dbcfd8cefdad53 --- Libraries/Animated/NativeAnimatedHelper.js | 2 +- Libraries/Animated/nodes/AnimatedValue.js | 2 +- Libraries/Animated/useAnimatedProps.js | 2 +- Libraries/Interaction/InteractionManager.js | 6 +++--- Libraries/ReactNative/PaperUIManager.js | 2 +- Libraries/Utilities/PolyfillFunctions.js | 2 +- .../react-native-codegen/src/SchemaValidator.js | 2 +- .../components/GeneratePropsJavaDelegate.js | 2 +- .../components/GeneratePropsJavaInterface.js | 2 +- .../generators/modules/GenerateModuleJavaSpec.js | 2 +- .../examples/RCTRootView/RCTRootViewIOSExample.js | 14 ++++++++------ 11 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Libraries/Animated/NativeAnimatedHelper.js b/Libraries/Animated/NativeAnimatedHelper.js index 704a4f6e1b7..a9ad27424dc 100644 --- a/Libraries/Animated/NativeAnimatedHelper.js +++ b/Libraries/Animated/NativeAnimatedHelper.js @@ -37,7 +37,7 @@ let __nativeAnimationIdCount = 1; /* used for started animations */ let nativeEventEmitter; -let waitingForQueuedOperations = new Set(); +let waitingForQueuedOperations = new Set(); let queueOperations = false; let queue: Array<() => void> = []; // $FlowFixMe diff --git a/Libraries/Animated/nodes/AnimatedValue.js b/Libraries/Animated/nodes/AnimatedValue.js index 63d91b48e33..f20307b310e 100644 --- a/Libraries/Animated/nodes/AnimatedValue.js +++ b/Libraries/Animated/nodes/AnimatedValue.js @@ -49,7 +49,7 @@ const NativeAnimatedAPI = NativeAnimatedHelper.API; * transform which can receive values from multiple parents. */ function _flush(rootNode: AnimatedValue): void { - const animatedStyles = new Set(); + const animatedStyles = new Set(); function findAnimatedStyles(node: AnimatedValue | AnimatedNode) { /* $FlowFixMe[prop-missing] (>=0.68.0 site=react_native_fb) This comment * suppresses an error found when Flow v0.68 was deployed. To see the error diff --git a/Libraries/Animated/useAnimatedProps.js b/Libraries/Animated/useAnimatedProps.js index 137a8de6200..1b7d81009fd 100644 --- a/Libraries/Animated/useAnimatedProps.js +++ b/Libraries/Animated/useAnimatedProps.js @@ -33,7 +33,7 @@ type CallbackRef = T => mixed; export default function useAnimatedProps( props: TProps, ): [ReducedProps, CallbackRef] { - const [, scheduleUpdate] = useReducer(count => count + 1, 0); + const [, scheduleUpdate] = useReducer(count => count + 1, 0); const onUpdateRef = useRef void>(null); // TODO: Only invalidate `node` if animated props or `style` change. In the diff --git a/Libraries/Interaction/InteractionManager.js b/Libraries/Interaction/InteractionManager.js index 216225f81ef..7415f84266e 100644 --- a/Libraries/Interaction/InteractionManager.js +++ b/Libraries/Interaction/InteractionManager.js @@ -150,9 +150,9 @@ const InteractionManager = { }, }; -const _interactionSet = new Set(); -const _addInteractionSet = new Set(); -const _deleteInteractionSet = new Set(); +const _interactionSet = new Set(); +const _addInteractionSet = new Set(); +const _deleteInteractionSet = new Set(); const _taskQueue = new TaskQueue({onMoreTasks: _scheduleUpdate}); let _nextUpdateHandle: $FlowFixMe | TimeoutID = 0; let _inc = 0; diff --git a/Libraries/ReactNative/PaperUIManager.js b/Libraries/ReactNative/PaperUIManager.js index 0247ca55ed3..2b1efffb456 100644 --- a/Libraries/ReactNative/PaperUIManager.js +++ b/Libraries/ReactNative/PaperUIManager.js @@ -19,7 +19,7 @@ const UIManagerProperties = require('./UIManagerProperties'); const viewManagerConfigs: {[string]: any | null} = {}; -const triedLoadingConfig = new Set(); +const triedLoadingConfig = new Set(); let NativeUIManagerConstants = {}; let isNativeUIManagerConstantsSet = false; diff --git a/Libraries/Utilities/PolyfillFunctions.js b/Libraries/Utilities/PolyfillFunctions.js index b09def25782..61c6d8b8d49 100644 --- a/Libraries/Utilities/PolyfillFunctions.js +++ b/Libraries/Utilities/PolyfillFunctions.js @@ -30,7 +30,7 @@ function polyfillObjectProperty( name: string, getValue: () => T, ): void { - const descriptor = Object.getOwnPropertyDescriptor(object, name); + const descriptor = Object.getOwnPropertyDescriptor<$FlowFixMe>(object, name); if (__DEV__ && descriptor) { const backupName = `original${name[0].toUpperCase()}${name.substr(1)}`; Object.defineProperty(object, backupName, descriptor); diff --git a/packages/react-native-codegen/src/SchemaValidator.js b/packages/react-native-codegen/src/SchemaValidator.js index 887c6eb60a9..87ded884845 100644 --- a/packages/react-native-codegen/src/SchemaValidator.js +++ b/packages/react-native-codegen/src/SchemaValidator.js @@ -15,7 +15,7 @@ const nullthrows = require('nullthrows'); import type {SchemaType} from './CodegenSchema'; function getErrors(schema: SchemaType): $ReadOnlyArray { - const errors = new Set(); + const errors = new Set(); // Map of component name -> Array of module names const componentModules: Map> = new Map(); diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js index bf058c1df18..a7504229207 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js @@ -296,7 +296,7 @@ module.exports = { const normalizedPackageName = 'com.facebook.react.viewmanagers'; const outputDir = `java/${normalizedPackageName.replace(/\./g, '/')}`; - const files = new Map(); + const files = new Map(); Object.keys(schema.modules).forEach(moduleName => { const module = schema.modules[moduleName]; if (module.type !== 'Component') { diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js index cdd50516478..d373e171224 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js @@ -235,7 +235,7 @@ module.exports = { const normalizedPackageName = 'com.facebook.react.viewmanagers'; const outputDir = `java/${normalizedPackageName.replace(/\./g, '/')}`; - const files = new Map(); + const files = new Map(); Object.keys(schema.modules).forEach(moduleName => { const module = schema.modules[moduleName]; if (module.type !== 'Component') { diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js index 0715932adbb..cfcf87c0597 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js @@ -373,7 +373,7 @@ module.exports = { packageName?: string, assumeNonnull: boolean = false, ): FilesOutput { - const files = new Map(); + const files = new Map(); const nativeModules = getModules(schema); const normalizedPackageName = diff --git a/packages/rn-tester/js/examples/RCTRootView/RCTRootViewIOSExample.js b/packages/rn-tester/js/examples/RCTRootView/RCTRootViewIOSExample.js index 2ad33878de2..576f5f020d0 100644 --- a/packages/rn-tester/js/examples/RCTRootView/RCTRootViewIOSExample.js +++ b/packages/rn-tester/js/examples/RCTRootView/RCTRootViewIOSExample.js @@ -21,9 +21,10 @@ const { class AppPropertiesUpdateExample extends React.Component<{...}> { render(): React.Node { // Do not require this unless we are actually rendering. - const UpdatePropertiesExampleView = requireNativeComponent( - 'UpdatePropertiesExampleView', - ); + const UpdatePropertiesExampleView = requireNativeComponent< + | any + | {children: React.MixedElement, style: {height: number, width: number}}, + >('UpdatePropertiesExampleView'); return ( @@ -43,9 +44,10 @@ class AppPropertiesUpdateExample extends React.Component<{...}> { class RootViewSizeFlexibilityExample extends React.Component<{...}> { render(): React.Node { // Do not require this unless we are actually rendering. - const FlexibleSizeExampleView = requireNativeComponent( - 'FlexibleSizeExampleView', - ); + const FlexibleSizeExampleView = requireNativeComponent< + | any + | {children: React.MixedElement, style: {height: number, width: number}}, + >('FlexibleSizeExampleView'); return (