diff --git a/packages/react-devtools-shared/src/node_modules/react-window/src/FixedSizeGrid.js b/packages/react-devtools-shared/src/node_modules/react-window/src/FixedSizeGrid.js index 685ad33478205..3f0b9f40676b9 100644 --- a/packages/react-devtools-shared/src/node_modules/react-window/src/FixedSizeGrid.js +++ b/packages/react-devtools-shared/src/node_modules/react-window/src/FixedSizeGrid.js @@ -1,10 +1,12 @@ // @flow +import type {ComponentType} from "react"; + import createGridComponent from './createGridComponent'; import type { Props, ScrollToAlign } from './createGridComponent'; -const FixedSizeGrid = createGridComponent({ +const FixedSizeGrid: ComponentType> = createGridComponent({ getColumnOffset: ({ columnWidth }: Props, index: number): number => index * ((columnWidth: any): number), diff --git a/packages/react-devtools-shared/src/node_modules/react-window/src/FixedSizeList.js b/packages/react-devtools-shared/src/node_modules/react-window/src/FixedSizeList.js index 0e0fc305bc301..5b6dab45988fb 100644 --- a/packages/react-devtools-shared/src/node_modules/react-window/src/FixedSizeList.js +++ b/packages/react-devtools-shared/src/node_modules/react-window/src/FixedSizeList.js @@ -1,10 +1,12 @@ // @flow +import type {ComponentType} from "react"; + import createListComponent from './createListComponent'; import type { Props, ScrollToAlign } from './createListComponent'; -const FixedSizeList = createListComponent({ +const FixedSizeList: ComponentType> = createListComponent({ getItemOffset: ({ itemSize }: Props, index: number): number => index * ((itemSize: any): number), diff --git a/packages/react-devtools-shared/src/node_modules/react-window/src/VariableSizeGrid.js b/packages/react-devtools-shared/src/node_modules/react-window/src/VariableSizeGrid.js index 2ce4f2d9a04ce..6b0d6a65e987a 100644 --- a/packages/react-devtools-shared/src/node_modules/react-window/src/VariableSizeGrid.js +++ b/packages/react-devtools-shared/src/node_modules/react-window/src/VariableSizeGrid.js @@ -1,5 +1,7 @@ // @flow +import type {ComponentType} from "react"; + import createGridComponent from './createGridComponent'; import type { Props, ScrollToAlign } from './createGridComponent'; @@ -286,7 +288,7 @@ const getOffsetForIndexAndAlignment = ( } }; -const VariableSizeGrid = createGridComponent({ +const VariableSizeGrid: ComponentType> = createGridComponent({ getColumnOffset: ( props: Props, index: number, diff --git a/packages/react-devtools-shared/src/node_modules/react-window/src/VariableSizeList.js b/packages/react-devtools-shared/src/node_modules/react-window/src/VariableSizeList.js index 887641b010eef..fa876ad994cbf 100644 --- a/packages/react-devtools-shared/src/node_modules/react-window/src/VariableSizeList.js +++ b/packages/react-devtools-shared/src/node_modules/react-window/src/VariableSizeList.js @@ -1,5 +1,7 @@ // @flow +import type {ComponentType} from "react"; + import createListComponent from './createListComponent'; import type { Props, ScrollToAlign } from './createListComponent'; @@ -163,7 +165,7 @@ const getEstimatedTotalSize = ( return totalSizeOfMeasuredItems + totalSizeOfUnmeasuredItems; }; -const VariableSizeList = createListComponent({ +const VariableSizeList: ComponentType> = createListComponent({ getItemOffset: ( props: Props, index: number, diff --git a/packages/react-dom-bindings/src/client/ReactDOMInput.js b/packages/react-dom-bindings/src/client/ReactDOMInput.js index 8d9ea1f45a431..ec03d75e37afb 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMInput.js +++ b/packages/react-dom-bindings/src/client/ReactDOMInput.js @@ -59,7 +59,7 @@ function isControlled(props) { * See http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html */ -export function getHostProps(element: Element, props: Object) { +export function getHostProps(element: Element, props: Object): Object { const node = ((element: any): InputWithWrapperState); const checked = props.checked; diff --git a/packages/react-dom-bindings/src/client/ReactDOMSelect.js b/packages/react-dom-bindings/src/client/ReactDOMSelect.js index 57f53b5206a82..3493879cf7989 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMSelect.js +++ b/packages/react-dom-bindings/src/client/ReactDOMSelect.js @@ -134,7 +134,7 @@ function updateOptions( * selected. */ -export function getHostProps(element: Element, props: Object) { +export function getHostProps(element: Element, props: Object): Object { return assign({}, props, { value: undefined, }); diff --git a/packages/react-dom-bindings/src/client/ReactDOMTextarea.js b/packages/react-dom-bindings/src/client/ReactDOMTextarea.js index 065f76d16c12d..4bf87f2e2340c 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMTextarea.js +++ b/packages/react-dom-bindings/src/client/ReactDOMTextarea.js @@ -37,7 +37,7 @@ type TextAreaWithWrapperState = HTMLTextAreaElement & { * `defaultValue` if specified, or the children content (deprecated). */ -export function getHostProps(element: Element, props: Object) { +export function getHostProps(element: Element, props: Object): Object { const node = ((element: any): TextAreaWithWrapperState); if (props.dangerouslySetInnerHTML != null) { diff --git a/packages/react-dom-bindings/src/client/setInnerHTML.js b/packages/react-dom-bindings/src/client/setInnerHTML.js index e283efb270770..fd4eb00748e95 100644 --- a/packages/react-dom-bindings/src/client/setInnerHTML.js +++ b/packages/react-dom-bindings/src/client/setInnerHTML.js @@ -21,7 +21,10 @@ let reusableSVGContainer; * @param {string} html * @internal */ -const setInnerHTML = createMicrosoftUnsafeLocalFunction(function( +const setInnerHTML: ( + node: Element, + html: {valueOf(): {toString(): string, ...}, ...}, +) => void = createMicrosoftUnsafeLocalFunction(function( node: Element, html: {valueOf(): {toString(): string, ...}, ...}, ): void { diff --git a/packages/react-dom-bindings/src/events/EventRegistry.js b/packages/react-dom-bindings/src/events/EventRegistry.js index eed8b9dc49845..f86948f8d5227 100644 --- a/packages/react-dom-bindings/src/events/EventRegistry.js +++ b/packages/react-dom-bindings/src/events/EventRegistry.js @@ -21,7 +21,9 @@ if (enableCreateEventHandleAPI) { /** * Mapping from registration name to event name */ -export const registrationNameDependencies = {}; +export const registrationNameDependencies: { + [registrationName: string]: Array, +} = {}; /** * Mapping from lowercase registration names to the properly cased version, @@ -29,7 +31,9 @@ export const registrationNameDependencies = {}; * only in __DEV__. * @type {Object} */ -export const possibleRegistrationNames = __DEV__ ? {} : (null: any); +export const possibleRegistrationNames: { + [lowerCasedName: string]: string, +} = __DEV__ ? {} : (null: any); // Trust the developer to only use possibleRegistrationNames in __DEV__ export function registerTwoPhaseEvent( diff --git a/packages/react-dom-bindings/src/events/ReactDOMEventListener.js b/packages/react-dom-bindings/src/events/ReactDOMEventListener.js index bd7e05b1d760e..ba2c1e63239de 100644 --- a/packages/react-dom-bindings/src/events/ReactDOMEventListener.js +++ b/packages/react-dom-bindings/src/events/ReactDOMEventListener.js @@ -8,7 +8,7 @@ */ import type {AnyNativeEvent} from '../events/PluginModuleType'; -import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes'; +import type {Fiber, FiberRoot} from 'react-reconciler/src/ReactInternalTypes'; import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig'; import type {DOMEventName} from '../events/DOMEventNames'; import {enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay} from 'shared/ReactFeatureFlags'; @@ -58,15 +58,15 @@ import {isRootDehydrated} from 'react-reconciler/src/ReactFiberShellHydration'; const {ReactCurrentBatchConfig} = ReactSharedInternals; // TODO: can we stop exporting these? -export let _enabled = true; +export let _enabled: boolean = true; // This is exported in FB builds for use by legacy FB layer infra. // We'd like to remove this but it's not clear if this is safe. -export function setEnabled(enabled: ?boolean) { +export function setEnabled(enabled: ?boolean): void { _enabled = !!enabled; } -export function isEnabled() { +export function isEnabled(): boolean { return _enabled; } @@ -348,7 +348,7 @@ function dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEve ); } -export let return_targetInst = null; +export let return_targetInst: null | Fiber = null; // Returns a SuspenseInstance or Container if it's blocked. // The return_targetInst field above is conceptually part of the return value. diff --git a/packages/react-dom-bindings/src/events/SyntheticEvent.js b/packages/react-dom-bindings/src/events/SyntheticEvent.js index 87bdad3548cdc..2d75b647aca80 100644 --- a/packages/react-dom-bindings/src/events/SyntheticEvent.js +++ b/packages/react-dom-bindings/src/events/SyntheticEvent.js @@ -16,7 +16,6 @@ import getEventCharCode from './getEventCharCode'; type EventInterfaceType = { [propName: string]: 0 | ((event: {[propName: string]: mixed, ...}) => mixed), - ..., }; function functionThatReturnsTrue() { @@ -153,14 +152,16 @@ const EventInterface = { defaultPrevented: 0, isTrusted: 0, }; -export const SyntheticEvent = createSyntheticEvent(EventInterface); +export const SyntheticEvent: $FlowFixMe = createSyntheticEvent(EventInterface); const UIEventInterface: EventInterfaceType = { ...EventInterface, view: 0, detail: 0, }; -export const SyntheticUIEvent = createSyntheticEvent(UIEventInterface); +export const SyntheticUIEvent: $FlowFixMe = createSyntheticEvent( + UIEventInterface, +); let lastMovementX; let lastMovementY; @@ -225,7 +226,9 @@ const MouseEventInterface: EventInterfaceType = { return lastMovementY; }, }; -export const SyntheticMouseEvent = createSyntheticEvent(MouseEventInterface); +export const SyntheticMouseEvent: $FlowFixMe = createSyntheticEvent( + MouseEventInterface, +); /** * @interface DragEvent @@ -235,7 +238,9 @@ const DragEventInterface: EventInterfaceType = { ...MouseEventInterface, dataTransfer: 0, }; -export const SyntheticDragEvent = createSyntheticEvent(DragEventInterface); +export const SyntheticDragEvent: $FlowFixMe = createSyntheticEvent( + DragEventInterface, +); /** * @interface FocusEvent @@ -245,7 +250,9 @@ const FocusEventInterface: EventInterfaceType = { ...UIEventInterface, relatedTarget: 0, }; -export const SyntheticFocusEvent = createSyntheticEvent(FocusEventInterface); +export const SyntheticFocusEvent: $FlowFixMe = createSyntheticEvent( + FocusEventInterface, +); /** * @interface Event @@ -258,7 +265,7 @@ const AnimationEventInterface: EventInterfaceType = { elapsedTime: 0, pseudoElement: 0, }; -export const SyntheticAnimationEvent = createSyntheticEvent( +export const SyntheticAnimationEvent: $FlowFixMe = createSyntheticEvent( AnimationEventInterface, ); @@ -274,7 +281,7 @@ const ClipboardEventInterface: EventInterfaceType = { : window.clipboardData; }, }; -export const SyntheticClipboardEvent = createSyntheticEvent( +export const SyntheticClipboardEvent: $FlowFixMe = createSyntheticEvent( ClipboardEventInterface, ); @@ -286,7 +293,7 @@ const CompositionEventInterface: EventInterfaceType = { ...EventInterface, data: 0, }; -export const SyntheticCompositionEvent = createSyntheticEvent( +export const SyntheticCompositionEvent: $FlowFixMe = createSyntheticEvent( CompositionEventInterface, ); @@ -487,7 +494,7 @@ const KeyboardEventInterface = { return 0; }, }; -export const SyntheticKeyboardEvent = createSyntheticEvent( +export const SyntheticKeyboardEvent: $FlowFixMe = createSyntheticEvent( KeyboardEventInterface, ); @@ -508,7 +515,7 @@ const PointerEventInterface = { pointerType: 0, isPrimary: 0, }; -export const SyntheticPointerEvent = createSyntheticEvent( +export const SyntheticPointerEvent: $FlowFixMe = createSyntheticEvent( PointerEventInterface, ); @@ -527,7 +534,9 @@ const TouchEventInterface = { shiftKey: 0, getModifierState: getEventModifierState, }; -export const SyntheticTouchEvent = createSyntheticEvent(TouchEventInterface); +export const SyntheticTouchEvent: $FlowFixMe = createSyntheticEvent( + TouchEventInterface, +); /** * @interface Event @@ -540,7 +549,7 @@ const TransitionEventInterface = { elapsedTime: 0, pseudoElement: 0, }; -export const SyntheticTransitionEvent = createSyntheticEvent( +export const SyntheticTransitionEvent: $FlowFixMe = createSyntheticEvent( TransitionEventInterface, ); @@ -580,4 +589,6 @@ const WheelEventInterface = { // ~40 pixels, for DOM_DELTA_SCREEN (2) it is 87.5% of viewport size. deltaMode: 0, }; -export const SyntheticWheelEvent = createSyntheticEvent(WheelEventInterface); +export const SyntheticWheelEvent: $FlowFixMe = createSyntheticEvent( + WheelEventInterface, +); diff --git a/packages/react-dom-bindings/src/events/forks/EventListener-www.js b/packages/react-dom-bindings/src/events/forks/EventListener-www.js index 04521613b5962..b9f20cca800ad 100644 --- a/packages/react-dom-bindings/src/events/forks/EventListener-www.js +++ b/packages/react-dom-bindings/src/events/forks/EventListener-www.js @@ -16,7 +16,7 @@ export function addEventBubbleListener( target: EventTarget, eventType: string, listener: Function, -) { +): mixed { return EventListenerWWW.listen(target, eventType, listener); } @@ -24,7 +24,7 @@ export function addEventCaptureListener( target: EventTarget, eventType: string, listener: Function, -) { +): mixed { return EventListenerWWW.capture(target, eventType, listener); } @@ -33,7 +33,7 @@ export function addEventCaptureListenerWithPassiveFlag( eventType: string, listener: Function, passive: boolean, -) { +): mixed { return EventListenerWWW.captureWithPassiveFlag( target, eventType, @@ -47,7 +47,7 @@ export function addEventBubbleListenerWithPassiveFlag( eventType: string, listener: Function, passive: boolean, -) { +): mixed { return EventListenerWWW.bubbleWithPassiveFlag( target, eventType, diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index 849bc283e01db..3f3265043e881 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -8,7 +8,10 @@ */ import type {ReactNodeList} from 'shared/ReactTypes'; -import type {Container} from 'react-dom-bindings/src/client/ReactDOMHostConfig'; +import type { + Container, + PublicInstance, +} from 'react-dom-bindings/src/client/ReactDOMHostConfig'; import type { RootType, HydrateRootOptions, @@ -125,7 +128,7 @@ function renderSubtreeIntoContainer( element: React$Element, containerNode: Container, callback: ?Function, -) { +): React$Component | PublicInstance | null { return unstable_renderSubtreeIntoContainer( parentComponent, element, @@ -171,7 +174,7 @@ declare function flushSync(fn: () => R): R; // eslint-disable-next-line no-redeclare declare function flushSync(): void; // eslint-disable-next-line no-redeclare -function flushSync(fn) { +function flushSync(fn: (() => R) | void): R | void { if (__DEV__) { if (isAlreadyRendering()) { console.error( diff --git a/packages/react-dom/src/client/ReactDOMLegacy.js b/packages/react-dom/src/client/ReactDOMLegacy.js index 7118ba1e871c7..92f1ff0cdca5f 100644 --- a/packages/react-dom/src/client/ReactDOMLegacy.js +++ b/packages/react-dom/src/client/ReactDOMLegacy.js @@ -7,7 +7,10 @@ * @flow */ -import type {Container} from 'react-dom-bindings/src/client/ReactDOMHostConfig'; +import type { + Container, + PublicInstance, +} from 'react-dom-bindings/src/client/ReactDOMHostConfig'; import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes'; import type {ReactNodeList} from 'shared/ReactTypes'; @@ -206,7 +209,7 @@ function legacyRenderSubtreeIntoContainer( container: Container, forceHydrate: boolean, callback: ?Function, -) { +): React$Component | PublicInstance | null { if (__DEV__) { topLevelUpdateWarnings(container); warnOnInvalidCallback(callback === undefined ? null : callback, 'render'); @@ -274,7 +277,7 @@ export function hydrate( element: React$Node, container: Container, callback: ?Function, -) { +): React$Component | PublicInstance | null { if (__DEV__) { console.error( 'ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot ' + @@ -314,7 +317,7 @@ export function render( element: React$Element, container: Container, callback: ?Function, -) { +): React$Component | PublicInstance | null { if (__DEV__) { console.error( 'ReactDOM.render is no longer supported in React 18. Use createRoot ' + @@ -354,7 +357,7 @@ export function unstable_renderSubtreeIntoContainer( element: React$Element, containerNode: Container, callback: ?Function, -) { +): React$Component | PublicInstance | null { if (__DEV__) { console.error( 'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported ' + @@ -381,7 +384,7 @@ export function unstable_renderSubtreeIntoContainer( ); } -export function unmountComponentAtNode(container: Container) { +export function unmountComponentAtNode(container: Container): boolean { if (!isValidContainerLegacy(container)) { throw new Error( 'unmountComponentAtNode(...): Target container is not a DOM element.', diff --git a/packages/react-native-renderer/src/ReactFabricHostConfig.js b/packages/react-native-renderer/src/ReactFabricHostConfig.js index d78339b8128ea..4284889658c5c 100644 --- a/packages/react-native-renderer/src/ReactFabricHostConfig.js +++ b/packages/react-native-renderer/src/ReactFabricHostConfig.js @@ -593,7 +593,7 @@ export function replaceContainerChildren( newChildren: ChildSet, ): void {} -export function getInstanceFromNode(node: any) { +export function getInstanceFromNode(node: any): empty { throw new Error('Not yet implemented.'); } diff --git a/packages/react-native-renderer/src/ReactNativeHostConfig.js b/packages/react-native-renderer/src/ReactNativeHostConfig.js index 5deae0672e6ba..26855bd87e838 100644 --- a/packages/react-native-renderer/src/ReactNativeHostConfig.js +++ b/packages/react-native-renderer/src/ReactNativeHostConfig.js @@ -492,7 +492,7 @@ export function unhideTextInstance( throw new Error('Not yet implemented.'); } -export function getInstanceFromNode(node: any) { +export function getInstanceFromNode(node: any): empty { throw new Error('Not yet implemented.'); } diff --git a/packages/react-native-renderer/src/legacy-events/accumulate.js b/packages/react-native-renderer/src/legacy-events/accumulate.js index 6d43ada04f0ef..9d4fe02b4793c 100644 --- a/packages/react-native-renderer/src/legacy-events/accumulate.js +++ b/packages/react-native-renderer/src/legacy-events/accumulate.js @@ -39,6 +39,8 @@ function accumulate( } if (isArray(next)) { + /* $FlowFixMe[incompatible-return] unsound if `next` is `T` and `T` an array, + * `isArray` might refine to the array element type of `T` */ return [current].concat(next); } diff --git a/packages/react-native-renderer/src/legacy-events/accumulateInto.js b/packages/react-native-renderer/src/legacy-events/accumulateInto.js index 7c9f17a757793..6016a1383dab3 100644 --- a/packages/react-native-renderer/src/legacy-events/accumulateInto.js +++ b/packages/react-native-renderer/src/legacy-events/accumulateInto.js @@ -51,6 +51,8 @@ function accumulateInto( if (isArray(next)) { // A bit too dangerous to mutate `next`. + /* $FlowFixMe[incompatible-return] unsound if `next` is `T` and `T` an array, + * `isArray` might refine to the array element type of `T` */ return [current].concat(next); } diff --git a/packages/react-reconciler/src/ReactFiberHostConfigWithNoHydration.js b/packages/react-reconciler/src/ReactFiberHostConfigWithNoHydration.js index f61c0eb7789e7..72d2c72fe2814 100644 --- a/packages/react-reconciler/src/ReactFiberHostConfigWithNoHydration.js +++ b/packages/react-reconciler/src/ReactFiberHostConfigWithNoHydration.js @@ -10,7 +10,7 @@ // Renderers that don't support hydration // can re-export everything from this module. -function shim(...args: any) { +function shim(...args: any): empty { throw new Error( 'The current renderer does not support hydration. ' + 'This error is likely caused by a bug in React. ' + diff --git a/packages/react-reconciler/src/ReactFiberHostConfigWithNoMicrotasks.js b/packages/react-reconciler/src/ReactFiberHostConfigWithNoMicrotasks.js index 5c55d9d59b01f..f50545747cffe 100644 --- a/packages/react-reconciler/src/ReactFiberHostConfigWithNoMicrotasks.js +++ b/packages/react-reconciler/src/ReactFiberHostConfigWithNoMicrotasks.js @@ -10,7 +10,7 @@ // Renderers that don't support microtasks // can re-export everything from this module. -function shim(...args: any) { +function shim(...args: any): empty { throw new Error( 'The current renderer does not support microtasks. ' + 'This error is likely caused by a bug in React. ' + diff --git a/packages/react-reconciler/src/ReactFiberHostConfigWithNoMutation.js b/packages/react-reconciler/src/ReactFiberHostConfigWithNoMutation.js index 59e8c450861f0..742e115f13334 100644 --- a/packages/react-reconciler/src/ReactFiberHostConfigWithNoMutation.js +++ b/packages/react-reconciler/src/ReactFiberHostConfigWithNoMutation.js @@ -10,7 +10,7 @@ // Renderers that don't support mutation // can re-export everything from this module. -function shim(...args: any) { +function shim(...args: any): empty { throw new Error( 'The current renderer does not support mutation. ' + 'This error is likely caused by a bug in React. ' + diff --git a/packages/react-reconciler/src/ReactFiberHostConfigWithNoPersistence.js b/packages/react-reconciler/src/ReactFiberHostConfigWithNoPersistence.js index c34449f6a2466..85d0d83caa533 100644 --- a/packages/react-reconciler/src/ReactFiberHostConfigWithNoPersistence.js +++ b/packages/react-reconciler/src/ReactFiberHostConfigWithNoPersistence.js @@ -10,7 +10,7 @@ // Renderers that don't support persistence // can re-export everything from this module. -function shim(...args: any) { +function shim(...args: any): empty { throw new Error( 'The current renderer does not support persistence. ' + 'This error is likely caused by a bug in React. ' + diff --git a/packages/react-reconciler/src/ReactFiberHostConfigWithNoResources.js b/packages/react-reconciler/src/ReactFiberHostConfigWithNoResources.js index b620a06b37fb9..1075834cb9bd0 100644 --- a/packages/react-reconciler/src/ReactFiberHostConfigWithNoResources.js +++ b/packages/react-reconciler/src/ReactFiberHostConfigWithNoResources.js @@ -10,7 +10,7 @@ // Renderers that don't support hydration // can re-export everything from this module. -function shim(...args: any) { +function shim(...args: any): empty { throw new Error( 'The current renderer does not support Resources. ' + 'This error is likely caused by a bug in React. ' + diff --git a/packages/react-reconciler/src/ReactFiberHostConfigWithNoScopes.js b/packages/react-reconciler/src/ReactFiberHostConfigWithNoScopes.js index 6eb3d08a4de64..3d4064ebfdb5f 100644 --- a/packages/react-reconciler/src/ReactFiberHostConfigWithNoScopes.js +++ b/packages/react-reconciler/src/ReactFiberHostConfigWithNoScopes.js @@ -10,7 +10,7 @@ // Renderers that don't support React Scopes // can re-export everything from this module. -function shim(...args: any) { +function shim(...args: any): empty { throw new Error( 'The current renderer does not support React Scopes. ' + 'This error is likely caused by a bug in React. ' + diff --git a/packages/react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors.js b/packages/react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors.js index 964bf4b2c43d5..a597ca526565d 100644 --- a/packages/react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors.js +++ b/packages/react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors.js @@ -10,7 +10,7 @@ // Renderers that don't support test selectors // can re-export everything from this module. -function shim(...args: any) { +function shim(...args: any): empty { throw new Error( 'The current renderer does not support test selectors. ' + 'This error is likely caused by a bug in React. ' + diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index e0add4c8db6fd..34b9d3f10c06b 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -1565,7 +1565,7 @@ export function discreteUpdates( // Warning, this opts-out of checking the function body. declare function flushSync(fn: () => R): R; // eslint-disable-next-line no-redeclare -declare function flushSync(): void; +declare function flushSync(void): void; // eslint-disable-next-line no-redeclare export function flushSync(fn: (() => R) | void): R | void { // In legacy mode, we flush pending passive effects at the beginning of the diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index e5774487dc2cf..b5cd4565ef104 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -1565,7 +1565,7 @@ export function discreteUpdates( // Warning, this opts-out of checking the function body. declare function flushSync(fn: () => R): R; // eslint-disable-next-line no-redeclare -declare function flushSync(): void; +declare function flushSync(void): void; // eslint-disable-next-line no-redeclare export function flushSync(fn: (() => R) | void): R | void { // In legacy mode, we flush pending passive effects at the beginning of the diff --git a/packages/react-test-renderer/src/ReactTestHostConfig.js b/packages/react-test-renderer/src/ReactTestHostConfig.js index 1db038e411286..e8daa8368f9e7 100644 --- a/packages/react-test-renderer/src/ReactTestHostConfig.js +++ b/packages/react-test-renderer/src/ReactTestHostConfig.js @@ -57,7 +57,7 @@ if (__DEV__) { Object.freeze(UPDATE_SIGNAL); } -export function getPublicInstance(inst: Instance | TextInstance): * { +export function getPublicInstance(inst: Instance | TextInstance): $FlowFixMe { switch (inst.tag) { case 'INSTANCE': const createNodeMock = inst.rootContainerInstance.createNodeMock; @@ -283,7 +283,7 @@ export function unhideTextInstance( textInstance.isHidden = false; } -export function getInstanceFromNode(mockNode: Object) { +export function getInstanceFromNode(mockNode: Object): Object | null { const instance = nodeToInstanceMap.get(mockNode); if (instance !== undefined) { return instance.internalInstanceHandle; diff --git a/packages/react-test-renderer/src/ReactTestRenderer.js b/packages/react-test-renderer/src/ReactTestRenderer.js index f8d8b8ca3a37a..f0ba1fce9c0b6 100644 --- a/packages/react-test-renderer/src/ReactTestRenderer.js +++ b/packages/react-test-renderer/src/ReactTestRenderer.js @@ -9,7 +9,11 @@ import type {Fiber} from 'react-reconciler/src/ReactInternalTypes'; import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes'; -import type {Instance, TextInstance} from './ReactTestHostConfig'; +import type { + PublicInstance, + Instance, + TextInstance, +} from './ReactTestHostConfig'; import * as React from 'react'; import * as Scheduler from 'scheduler/unstable_mock'; @@ -303,7 +307,7 @@ class ReactTestInstance { this._fiber = fiber; } - get instance() { + get instance(): $FlowFixMe { if (this._fiber.tag === HostComponent || this._fiber.tag === HostResource) { return getPublicInstance(this._fiber.stateNode); } else { @@ -311,7 +315,7 @@ class ReactTestInstance { } } - get type() { + get type(): any { return this._fiber.type; } @@ -445,7 +449,19 @@ function onRecoverableError(error) { console.error(error); } -function create(element: React$Element, options: TestRendererOptions) { +function create( + element: React$Element, + options: TestRendererOptions, +): { + _Scheduler: typeof Scheduler, + root: void, + toJSON(): Array | ReactTestRendererNode | null, + toTree(): mixed, + update(newElement: React$Element): any, + unmount(): void, + getInstance(): React$Component | PublicInstance | null, + unstable_flushSync: typeof flushSync, +} { let createNodeMock = defaultTestOptions.createNodeMock; let isConcurrent = false; let isStrictMode = false; @@ -534,7 +550,7 @@ function create(element: React$Element, options: TestRendererOptions) { } return toTree(root.current); }, - update(newElement: React$Element) { + update(newElement: React$Element): number | void { if (root == null || root.current == null) { return; } diff --git a/packages/react/src/React.js b/packages/react/src/React.js index fc6c77cbb6539..5edcd9e83049b 100644 --- a/packages/react/src/React.js +++ b/packages/react/src/React.js @@ -71,9 +71,15 @@ import {startTransition} from './ReactStartTransition'; import {act} from './ReactAct'; // TODO: Move this branching into the other module instead and just re-export. -const createElement = __DEV__ ? createElementWithValidation : createElementProd; -const cloneElement = __DEV__ ? cloneElementWithValidation : cloneElementProd; -const createFactory = __DEV__ ? createFactoryWithValidation : createFactoryProd; +const createElement: any = __DEV__ + ? createElementWithValidation + : createElementProd; +const cloneElement: any = __DEV__ + ? cloneElementWithValidation + : cloneElementProd; +const createFactory: any = __DEV__ + ? createFactoryWithValidation + : createFactoryProd; const Children = { map, diff --git a/packages/react/src/ReactDebugCurrentFrame.js b/packages/react/src/ReactDebugCurrentFrame.js index ddaeed70f99b7..557a4cd56abc6 100644 --- a/packages/react/src/ReactDebugCurrentFrame.js +++ b/packages/react/src/ReactDebugCurrentFrame.js @@ -7,11 +7,17 @@ * @flow */ -const ReactDebugCurrentFrame = {}; +const ReactDebugCurrentFrame: { + setExtraStackFrame?: (stack: null | string) => void, + getCurrentStack?: null | (() => string), + getStackAddendum?: () => string, +} = + // $FlowFixMe[incompatible-exact] + {}; let currentExtraStackFrame = (null: null | string); -export function setExtraStackFrame(stack: null | string) { +export function setExtraStackFrame(stack: null | string): void { if (__DEV__) { currentExtraStackFrame = stack; } diff --git a/packages/react/src/jsx/ReactJSX.js b/packages/react/src/jsx/ReactJSX.js index a4e8f63dedd74..f0134421ec51f 100644 --- a/packages/react/src/jsx/ReactJSX.js +++ b/packages/react/src/jsx/ReactJSX.js @@ -13,10 +13,10 @@ import { jsxWithValidation, } from './ReactJSXElementValidator'; import {jsx as jsxProd} from './ReactJSXElement'; -const jsx = __DEV__ ? jsxWithValidationDynamic : jsxProd; +const jsx: any = __DEV__ ? jsxWithValidationDynamic : jsxProd; // we may want to special case jsxs internally to take advantage of static children. // for now we can ship identical prod functions -const jsxs = __DEV__ ? jsxWithValidationStatic : jsxProd; -const jsxDEV = __DEV__ ? jsxWithValidation : undefined; +const jsxs: any = __DEV__ ? jsxWithValidationStatic : jsxProd; +const jsxDEV: any = __DEV__ ? jsxWithValidation : undefined; export {REACT_FRAGMENT_TYPE as Fragment, jsx, jsxs, jsxDEV}; diff --git a/scripts/flow/config/flowconfig b/scripts/flow/config/flowconfig index 68e1aef4a3408..0299da6337508 100644 --- a/scripts/flow/config/flowconfig +++ b/scripts/flow/config/flowconfig @@ -45,46 +45,8 @@ esproposal.class_instance_fields=enable esproposal.optional_chaining=enable exact_by_default=true munge_underscores=false -types_first=false - +types_first=true well_formed_exports=true -well_formed_exports.includes=/packages/dom-event-testing-library -well_formed_exports.includes=/packages/eslint-plugin-react-hooks -well_formed_exports.includes=/packages/jest-mock-scheduler -well_formed_exports.includes=/packages/jest-react -; well_formed_exports.includes=/packages/react -well_formed_exports.includes=/packages/react-art -well_formed_exports.includes=/packages/react-cache -well_formed_exports.includes=/packages/react-client -well_formed_exports.includes=/packages/react-debug-tools -well_formed_exports.includes=/packages/react-devtools -well_formed_exports.includes=/packages/react-devtools-core -well_formed_exports.includes=/packages/react-devtools-extensions -well_formed_exports.includes=/packages/react-devtools-inline -well_formed_exports.includes=/packages/react-devtools-shared -well_formed_exports.includes=/packages/react-devtools-shell -well_formed_exports.includes=/packages/react-devtools-timeline -; well_formed_exports.includes=/packages/react-dom -; well_formed_exports.includes=/packages/react-dom-bindings -well_formed_exports.includes=/packages/react-fetch -well_formed_exports.includes=/packages/react-fs -well_formed_exports.includes=/packages/react-interactions -well_formed_exports.includes=/packages/react-is -well_formed_exports.includes=/packages/react-native-renderer -well_formed_exports.includes=/packages/react-noop-renderer -well_formed_exports.includes=/packages/react-pg -well_formed_exports.includes=/packages/react-reconciler -well_formed_exports.includes=/packages/react-refresh -well_formed_exports.includes=/packages/react-server -well_formed_exports.includes=/packages/react-server-dom-relay -well_formed_exports.includes=/packages/react-server-dom-webpack -well_formed_exports.includes=/packages/react-server-native-relay -well_formed_exports.includes=/packages/react-suspense-test-utils -; well_formed_exports.includes=/packages/react-test-renderer -well_formed_exports.includes=/packages/scheduler -well_formed_exports.includes=/packages/shared -well_formed_exports.includes=/packages/use-subscription -well_formed_exports.includes=/packages/use-sync-external-store # Substituted by createFlowConfig.js: %REACT_RENDERER_FLOW_OPTIONS%