From 85fb95cdffdd95f2f908ee71974cae06b1c866e1 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Fri, 16 Aug 2024 12:53:52 -0400 Subject: [PATCH] [flow] Eliminate a few React.Element type that will be synced to react-native (#30719) ## Summary Flow will eventually remove the specific `React.Element` type. For most of the code, it can be replaced with `React.MixedElement` or `React.Node`. When specific react elements are required, it needs to be replaced with either `React$Element` which will trigger a `internal-type` lint error that can be disabled project-wide, or use `ExactReactElement_DEPRECATED`. Fortunately in this case, this one can be replaced with just `React.MixedElement`. ## How did you test this change? `flow` --- .../react-native-renderer/src/ReactNativeRenderer.js | 4 ++-- .../react-native-renderer/src/ReactNativeTypes.js | 11 ++++++++--- packages/react/index.js | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 983079fd0e..4ec5ab2c58 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -8,7 +8,7 @@ */ import type {ReactPortal, ReactNodeList} from 'shared/ReactTypes'; -import type {ElementRef, Element, ElementType} from 'react'; +import type {ElementRef, ElementType, MixedElement} from 'react'; import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes'; import type {RenderRootOptions} from './ReactNativeTypes'; @@ -117,7 +117,7 @@ function nativeOnCaughtError( } function render( - element: Element, + element: MixedElement, containerTag: number, callback: ?() => void, options: ?RenderRootOptions, diff --git a/packages/react-native-renderer/src/ReactNativeTypes.js b/packages/react-native-renderer/src/ReactNativeTypes.js index 917e3988c7..2103668423 100644 --- a/packages/react-native-renderer/src/ReactNativeTypes.js +++ b/packages/react-native-renderer/src/ReactNativeTypes.js @@ -9,7 +9,12 @@ * @flow strict */ -import type {ElementRef, ElementType, Element, AbstractComponent} from 'react'; +import type { + ElementRef, + ElementType, + MixedElement, + AbstractComponent, +} from 'react'; export type MeasureOnSuccessCallback = ( x: number, @@ -221,7 +226,7 @@ export type ReactNativeType = { eventType: string, ): void, render( - element: Element, + element: MixedElement, containerTag: number, callback: ?() => void, options: ?RenderRootOptions, @@ -256,7 +261,7 @@ export type ReactFabricType = { eventType: string, ): void, render( - element: Element, + element: MixedElement, containerTag: number, callback: ?() => void, concurrentRoot: ?boolean, diff --git a/packages/react/index.js b/packages/react/index.js index bad2c40e6c..19f256fd73 100644 --- a/packages/react/index.js +++ b/packages/react/index.js @@ -15,6 +15,7 @@ export type AbstractComponent< > = React$AbstractComponent; export type ElementType = React$ElementType; export type Element<+C> = React$Element; +export type MixedElement = React$Element; export type Key = React$Key; export type Ref = React$Ref; export type Node = React$Node;