diff --git a/flow-typed/npm/react-dom_v17.x.x.js b/flow-typed/npm/react-dom_v17.x.x.js index 7c5fe5329e9..cc2f334626f 100644 --- a/flow-typed/npm/react-dom_v17.x.x.js +++ b/flow-typed/npm/react-dom_v17.x.x.js @@ -1,29 +1,28 @@ -// flow-typed signature: e556c06e721548417501c08b01fec911 -// flow-typed version: ad3adf2de8/react-dom_v17.x.x/flow_>=v0.127.x - declare module 'react-dom' { + import type {Component} from 'react'; + declare var version: string; declare function findDOMNode( - componentOrElement: Element | ?React$Component + componentOrElement: Element | ?Component ): null | Element | Text; - declare function render( - element: React$Element, + declare function render( + element: ExactReactElement_DEPRECATED, container: Element, callback?: () => void - ): React$ElementRef; + ): React.ElementRef; - declare function hydrate( - element: React$Element, + declare function hydrate( + element: ExactReactElement_DEPRECATED, container: Element, callback?: () => void - ): React$ElementRef; + ): React.ElementRef; declare function createPortal( - node: React$Node, + node: React.Node, container: Element - ): React$Portal; + ): React.Portal; declare function unmountComponentAtNode(container: any): boolean; @@ -37,30 +36,32 @@ declare module 'react-dom' { ): void; declare function unstable_renderSubtreeIntoContainer< - ElementType: React$ElementType + ElementType: React.ElementType >( - parentComponent: React$Component, - nextElement: React$Element, + parentComponent: Component, + nextElement: ExactReactElement_DEPRECATED, container: any, callback?: () => void - ): React$ElementRef; + ): React.ElementRef; } declare module 'react-dom/server' { declare var version: string; - declare function renderToString(element: React$Node): string; + declare function renderToString(element: React.Node): string; - declare function renderToStaticMarkup(element: React$Node): string; + declare function renderToStaticMarkup(element: React.Node): string; - declare function renderToNodeStream(element: React$Node): stream$Readable; + declare function renderToNodeStream(element: React.Node): stream$Readable; declare function renderToStaticNodeStream( - element: React$Node + element: React.Node ): stream$Readable; } declare module 'react-dom/test-utils' { + import type {Component} from 'react'; + declare interface Thenable { then(resolve: () => mixed, reject?: () => mixed): mixed, } @@ -74,66 +75,66 @@ declare module 'react-dom/test-utils' { }; declare function renderIntoDocument( - instance: React$Element - ): React$Component; + instance: React.MixedElement + ): Component; declare function mockComponent( - componentClass: React$ElementType, + componentClass: React.ElementType, mockTagName?: string ): { [key: string]: mixed, ... }; - declare function isElement(element: React$Element): boolean; + declare function isElement(element: React.MixedElement): boolean; declare function isElementOfType( - element: React$Element, - componentClass: React$ElementType + element: React.MixedElement, + componentClass: React.ElementType ): boolean; declare function isDOMComponent(instance: any): boolean; declare function isCompositeComponent( - instance: React$Component + instance: Component ): boolean; declare function isCompositeComponentWithType( - instance: React$Component, - componentClass: React$ElementType + instance: Component, + componentClass: React.ElementType ): boolean; declare function findAllInRenderedTree( - tree: React$Component, - test: (child: React$Component) => boolean - ): Array>; + tree: Component, + test: (child: Component) => boolean + ): Array>; declare function scryRenderedDOMComponentsWithClass( - tree: React$Component, + tree: Component, className: string ): Array; declare function findRenderedDOMComponentWithClass( - tree: React$Component, + tree: Component, className: string ): ?Element; declare function scryRenderedDOMComponentsWithTag( - tree: React$Component, + tree: Component, tagName: string ): Array; declare function findRenderedDOMComponentWithTag( - tree: React$Component, + tree: Component, tagName: string ): ?Element; declare function scryRenderedComponentsWithType( - tree: React$Component, - componentClass: React$ElementType - ): Array>; + tree: Component, + componentClass: React.ElementType + ): Array>; declare function findRenderedComponentWithType( - tree: React$Component, - componentClass: React$ElementType - ): ?React$Component; + tree: Component, + componentClass: React.ElementType + ): ?Component; declare function act(callback: () => void | Thenable): Thenable; } diff --git a/flow-typed/npm/react-test-renderer_v16.x.x.js b/flow-typed/npm/react-test-renderer_v16.x.x.js index 406dbafc0bf..e27d1a6d211 100644 --- a/flow-typed/npm/react-test-renderer_v16.x.x.js +++ b/flow-typed/npm/react-test-renderer_v16.x.x.js @@ -1,50 +1,52 @@ // Type definitions for react-test-renderer 16.x.x // Ported from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-test-renderer -type ReactComponentInstance = React$Component; - -type ReactTestRendererJSON = { - type: string, - props: { [propName: string]: any, ... }, - children: null | ReactTestRendererJSON[], - ... -}; - -type ReactTestRendererTree = ReactTestRendererJSON & { - nodeType: "component" | "host", - instance: ?ReactComponentInstance, - rendered: null | ReactTestRendererTree, - ... -}; - -type ReactTestInstance = { - instance: ?ReactComponentInstance, - type: string, - props: { [propName: string]: any, ... }, - parent: null | ReactTestInstance, - children: Array, - find(predicate: (node: ReactTestInstance) => boolean): ReactTestInstance, - findByType(type: React$ElementType): ReactTestInstance, - findByProps(props: { [propName: string]: any, ... }): ReactTestInstance, - findAll( - predicate: (node: ReactTestInstance) => boolean, - options?: { deep: boolean, ... } - ): ReactTestInstance[], - findAllByType( - type: React$ElementType, - options?: { deep: boolean, ... } - ): ReactTestInstance[], - findAllByProps( - props: { [propName: string]: any, ... }, - options?: { deep: boolean, ... } - ): ReactTestInstance[], - ... -}; - type TestRendererOptions = { createNodeMock(element: React.MixedElement): any, ... }; declare module "react-test-renderer" { - declare export type ReactTestRenderer = { + import type {Component as ReactComponent} from 'react'; + + type ReactComponentInstance = ReactComponent; + + export type ReactTestRendererJSON = { + type: string, + props: { [propName: string]: any, ... }, + children: null | ReactTestRendererJSON[], + ... + }; + + export type ReactTestRendererTree = ReactTestRendererJSON & { + nodeType: "component" | "host", + instance: ?ReactComponentInstance, + rendered: null | ReactTestRendererTree, + ... + }; + + export type ReactTestInstance = { + instance: ?ReactComponentInstance, + type: string, + props: { [propName: string]: any, ... }, + parent: null | ReactTestInstance, + children: Array, + find(predicate: (node: ReactTestInstance) => boolean): ReactTestInstance, + findByType(type: React.ElementType): ReactTestInstance, + findByProps(props: { [propName: string]: any, ... }): ReactTestInstance, + findAll( + predicate: (node: ReactTestInstance) => boolean, + options?: { deep: boolean, ... } + ): ReactTestInstance[], + findAllByType( + type: React.ElementType, + options?: { deep: boolean, ... } + ): ReactTestInstance[], + findAllByProps( + props: { [propName: string]: any, ... }, + options?: { deep: boolean, ... } + ): ReactTestInstance[], + ... + }; + + export type ReactTestRenderer = { toJSON(): null | ReactTestRendererJSON, toTree(): null | ReactTestRendererTree, unmount(nextElement?: React.MixedElement): void, @@ -65,6 +67,8 @@ declare module "react-test-renderer" { } declare module "react-test-renderer/shallow" { + import type {ReactTestInstance} from 'react-test-renderer'; + declare export default class ShallowRenderer { static createRenderer(): ShallowRenderer; getMountedInstance(): ReactTestInstance; diff --git a/packages/react-native/Libraries/ReactNative/AppRegistry.js b/packages/react-native/Libraries/ReactNative/AppRegistry.js index dff4e625ba0..b535506edfe 100644 --- a/packages/react-native/Libraries/ReactNative/AppRegistry.js +++ b/packages/react-native/Libraries/ReactNative/AppRegistry.js @@ -30,11 +30,11 @@ export type TaskProvider = () => Task; type TaskCanceller = () => void; type TaskCancelProvider = () => TaskCanceller; -export type ComponentProvider = () => React$ComponentType; +export type ComponentProvider = () => React.ComponentType; export type ComponentProviderInstrumentationHook = ( component_: ComponentProvider, scopedPerformanceLogger: IPerformanceLogger, -) => React$ComponentType; +) => React.ComponentType; export type AppConfig = { appKey: string, component?: ComponentProvider, @@ -59,7 +59,7 @@ export type Registry = { }; export type WrapperComponentProvider = ( appParameters: Object, -) => React$ComponentType; +) => React.ComponentType; export type RootViewStyleProvider = (appParameters: Object) => ViewStyleProp; const runnables: Runnables = {}; diff --git a/packages/react-native/Libraries/ReactNative/RootTag.js b/packages/react-native/Libraries/ReactNative/RootTag.js index 693fa31cbb7..c1b655d21c9 100644 --- a/packages/react-native/Libraries/ReactNative/RootTag.js +++ b/packages/react-native/Libraries/ReactNative/RootTag.js @@ -12,7 +12,7 @@ import * as React from 'react'; export opaque type RootTag = number; -export const RootTagContext: React$Context = +export const RootTagContext: React.Context = React.createContext(0); if (__DEV__) { diff --git a/packages/react-native/Libraries/Text/TextAncestor.js b/packages/react-native/Libraries/Text/TextAncestor.js index b7856be6168..105ee7d4883 100644 --- a/packages/react-native/Libraries/Text/TextAncestor.js +++ b/packages/react-native/Libraries/Text/TextAncestor.js @@ -15,7 +15,7 @@ const React = require('react'); /** * Whether the current element is the descendant of a element. */ -const TextAncestorContext: React$Context = React.createContext(false); +const TextAncestorContext: React.Context = React.createContext(false); if (__DEV__) { TextAncestorContext.displayName = 'TextAncestorContext'; } diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index 09e0fdf9a69..edf733b61b7 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -6533,11 +6533,11 @@ exports[`public API should not change unintentionally Libraries/ReactNative/AppR export type TaskProvider = () => Task; type TaskCanceller = () => void; type TaskCancelProvider = () => TaskCanceller; -export type ComponentProvider = () => React$ComponentType; +export type ComponentProvider = () => React.ComponentType; export type ComponentProviderInstrumentationHook = ( component_: ComponentProvider, scopedPerformanceLogger: IPerformanceLogger -) => React$ComponentType; +) => React.ComponentType; export type AppConfig = { appKey: string, component?: ComponentProvider, @@ -6562,7 +6562,7 @@ export type Registry = { }; export type WrapperComponentProvider = ( appParameters: Object -) => React$ComponentType; +) => React.ComponentType; export type RootViewStyleProvider = (appParameters: Object) => ViewStyleProp; declare const AppRegistry: { setWrapperComponentProvider(provider: WrapperComponentProvider): void, @@ -6878,7 +6878,7 @@ exports[`public API should not change unintentionally Libraries/ReactNative/Rend exports[`public API should not change unintentionally Libraries/ReactNative/RootTag.js 1`] = ` "declare export opaque type RootTag; -declare export const RootTagContext: React$Context; +declare export const RootTagContext: React.Context; declare export function createRootTag(rootTag: number | RootTag): RootTag; " `; @@ -7679,7 +7679,8 @@ declare export default typeof Text; `; exports[`public API should not change unintentionally Libraries/Text/TextAncestor.js 1`] = ` -"declare const TextAncestorContext: React$Context; +"declare const React: $FlowFixMe; +declare const TextAncestorContext: React.Context; declare export default typeof TextAncestorContext; " `; diff --git a/packages/react-native/flow/react.js b/packages/react-native/flow/react.js deleted file mode 100644 index 4a94675553b..00000000000 --- a/packages/react-native/flow/react.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict - * @nolint - * @format - */ - -declare opaque type React$Element< - +ElementType: React$ElementType, - +P = React$ElementProps, ->: {...}; diff --git a/packages/react-native/src/private/renderer/errorhandling/ErrorHandlers.js b/packages/react-native/src/private/renderer/errorhandling/ErrorHandlers.js index 2362e286784..cf9bb57a03d 100644 --- a/packages/react-native/src/private/renderer/errorhandling/ErrorHandlers.js +++ b/packages/react-native/src/private/renderer/errorhandling/ErrorHandlers.js @@ -9,6 +9,7 @@ */ import type {ExtendedError} from '../../../../Libraries/Core/ExtendedError'; +import type {Component as ReactComponent} from 'react'; import ExceptionsManager, { SyntheticError, @@ -17,7 +18,7 @@ import ExceptionsManager, { type ErrorInfo = { +componentStack?: ?string, // $FlowFixMe[unclear-type] unknown props and state. - +errorBoundary?: ?React$Component, + +errorBoundary?: ?ReactComponent, }; function getExtendedError( diff --git a/packages/rn-tester/js/examples/TurboModule/NativeCxxModuleExampleExample.js b/packages/rn-tester/js/examples/TurboModule/NativeCxxModuleExampleExample.js index f4f32dbf5dc..60357a12583 100644 --- a/packages/rn-tester/js/examples/TurboModule/NativeCxxModuleExampleExample.js +++ b/packages/rn-tester/js/examples/TurboModule/NativeCxxModuleExampleExample.js @@ -72,7 +72,7 @@ type ErrorExamples = | 'promiseAssert'; class NativeCxxModuleExampleExample extends React.Component<{}, State> { - static contextType: React$Context = RootTagContext; + static contextType: React.Context = RootTagContext; eventSubscriptions: EventSubscription[] = []; state: State = { diff --git a/packages/rn-tester/js/examples/TurboModule/SampleLegacyModuleExample.js b/packages/rn-tester/js/examples/TurboModule/SampleLegacyModuleExample.js index 58227b95e7d..503d93c6fa2 100644 --- a/packages/rn-tester/js/examples/TurboModule/SampleLegacyModuleExample.js +++ b/packages/rn-tester/js/examples/TurboModule/SampleLegacyModuleExample.js @@ -68,7 +68,7 @@ function stringify(obj: mixed): string { } class SampleLegacyModuleExample extends React.Component<{}, State> { - static contextType: React$Context = RootTagContext; + static contextType: React.Context = RootTagContext; state: State = { testResults: {}, diff --git a/packages/rn-tester/js/examples/TurboModule/SampleTurboModuleExample.js b/packages/rn-tester/js/examples/TurboModule/SampleTurboModuleExample.js index 9af1b932694..3fbe4a9ac41 100644 --- a/packages/rn-tester/js/examples/TurboModule/SampleTurboModuleExample.js +++ b/packages/rn-tester/js/examples/TurboModule/SampleTurboModuleExample.js @@ -63,7 +63,7 @@ type ErrorExamples = | 'promiseAssert'; class SampleTurboModuleExample extends React.Component<{}, State> { - static contextType: React$Context = RootTagContext; + static contextType: React.Context = RootTagContext; eventSubscriptions: EventSubscription[] = []; state: State = {