@samitouri / QOS-React / commits / 9518f11856

Root import types from react-native in ReactNativeTypes (#33063)

Dawid Małecki committed May 8, 2025 at 13:12 UTC 9518f1185621aecb99fd72385cdb137c6e8bd8fe
2 files changed +34 -27
packages/react-native-renderer/src/ReactNativeTypes.js
+20 -24
@@ -9,22 +9,18 @@
9 * @flow strict
10 */
11
12 -import type {
13 - Component as ReactComponent,
14 - ElementRef,
15 - ElementType,
16 - MixedElement,
17 -} from 'react';
12 import type {
13 // $FlowFixMe[nonstrict-import] TODO(@rubennorte)
20 - MeasureOnSuccessCallback,
14 + HostInstance as PublicInstance,
15 // $FlowFixMe[nonstrict-import] TODO(@rubennorte)
22 - PublicInstance,
16 + MeasureOnSuccessCallback,
17 // $FlowFixMe[nonstrict-import] TODO(@rubennorte)
18 PublicRootInstance,
19 // $FlowFixMe[nonstrict-import] TODO(@rubennorte)
20 PublicTextInstance,
27 -} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
21 +} from 'react-native';
22 +
23 +import * as React from 'react';
24
25 export type AttributeType<T, V> =
26 | true
@@ -96,8 +92,8 @@ type InspectorDataProps = $ReadOnly<{
92 }>;
93
94 type InspectorDataGetter = (
99 - <TElementType: ElementType>(
100 - componentOrHandle: ElementRef<TElementType> | number,
95 + <TElementType: React.ElementType>(
96 + componentOrHandle: React.ElementRef<TElementType> | number,
97 ) => ?number,
98 ) => $ReadOnly<{
99 measure: (callback: MeasureOnSuccessCallback) => void,
@@ -140,7 +136,7 @@ export type RenderRootOptions = {
136 +componentStack?: ?string,
137 // $FlowFixMe[unclear-type] unknown props and state.
138 // $FlowFixMe[value-as-type] Component in react repo is any-typed, but it will be well typed externally.
143 - +errorBoundary?: ?ReactComponent<any, any>,
139 + +errorBoundary?: ?React.Component<any, any>,
140 },
141 ) => void,
142 onRecoverableError?: (
@@ -154,11 +150,11 @@ export type RenderRootOptions = {
150 * Provide minimal Flow typing for the high-level RN API and call it a day.
151 */
152 export type ReactNativeType = {
157 - findHostInstance_DEPRECATED<TElementType: ElementType>(
158 - componentOrHandle: ?(ElementRef<TElementType> | number),
153 + findHostInstance_DEPRECATED<TElementType: React.ElementType>(
154 + componentOrHandle: ?(React.ElementRef<TElementType> | number),
155 ): ?PublicInstance,
160 - findNodeHandle<TElementType: ElementType>(
161 - componentOrHandle: ?(ElementRef<TElementType> | number),
156 + findNodeHandle<TElementType: React.ElementType>(
157 + componentOrHandle: ?(React.ElementRef<TElementType> | number),
158 ): ?number,
159 isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
160 dispatchCommand(
@@ -168,11 +164,11 @@ export type ReactNativeType = {
164 ): void,
165 sendAccessibilityEvent(handle: PublicInstance, eventType: string): void,
166 render(
171 - element: MixedElement,
167 + element: React.MixedElement,
168 containerTag: number,
169 callback: ?() => void,
170 options: ?RenderRootOptions,
175 - ): ?ElementRef<ElementType>,
171 + ): ?React.ElementRef<React.ElementType>,
172 unmountComponentAtNode(containerTag: number): void,
173 unmountComponentAtNodeAndRemoveContainer(containerTag: number): void,
174 +unstable_batchedUpdates: <T>(fn: (T) => void, bookkeeping: T) => void,
@@ -183,11 +179,11 @@ export opaque type Node = mixed;
179 export opaque type InternalInstanceHandle = mixed;
180
181 export type ReactFabricType = {
186 - findHostInstance_DEPRECATED<TElementType: ElementType>(
187 - componentOrHandle: ?(ElementRef<TElementType> | number),
182 + findHostInstance_DEPRECATED<TElementType: React.ElementType>(
183 + componentOrHandle: ?(React.ElementRef<TElementType> | number),
184 ): ?PublicInstance,
189 - findNodeHandle<TElementType: ElementType>(
190 - componentOrHandle: ?(ElementRef<TElementType> | number),
185 + findNodeHandle<TElementType: React.ElementType>(
186 + componentOrHandle: ?(React.ElementRef<TElementType> | number),
187 ): ?number,
188 dispatchCommand(
189 handle: PublicInstance,
@@ -197,12 +193,12 @@ export type ReactFabricType = {
193 isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
194 sendAccessibilityEvent(handle: PublicInstance, eventType: string): void,
195 render(
200 - element: MixedElement,
196 + element: React.MixedElement,
197 containerTag: number,
198 callback: ?() => void,
199 concurrentRoot: ?boolean,
200 options: ?RenderRootOptions,
205 - ): ?ElementRef<ElementType>,
201 + ): ?React.ElementRef<React.ElementType>,
202 unmountComponentAtNode(containerTag: number): void,
203 getNodeFromInternalInstanceHandle(
204 internalInstanceHandle: InternalInstanceHandle,
scripts/flow/react-native-host-hooks.js
+14 -3
@@ -50,6 +50,10 @@ type RawEventEmitterEvent = $ReadOnly<{
50 nativeEvent: {[string]: mixed, ...},
51 }>;
52
53 +declare opaque type __PublicInstance;
54 +declare opaque type __PublicTextInstance;
55 +declare opaque type __PublicRootInstance;
56 +
57 declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' {
58 declare export function deepDiffer(
59 one: any,
@@ -158,9 +162,9 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
162 emit: (channel: string, event: RawEventEmitterEvent) => string,
163 ...
164 };
161 - declare export opaque type PublicInstance;
162 - declare export opaque type PublicTextInstance;
163 - declare export opaque type PublicRootInstance;
165 + declare export type PublicInstance = __PublicInstance;
166 + declare export type PublicTextInstance = __PublicTextInstance;
167 + declare export type PublicRootInstance = __PublicRootInstance;
168 declare export type MeasureOnSuccessCallback = __MeasureOnSuccessCallback;
169 declare export type MeasureInWindowOnSuccessCallback =
170 __MeasureInWindowOnSuccessCallback;
@@ -204,6 +208,13 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
208 declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore' {
209 }
210
211 +declare module 'react-native' {
212 + declare export type HostInstance = __PublicInstance;
213 + declare export type PublicTextInstance = __PublicTextInstance;
214 + declare export type PublicRootInstance = __PublicRootInstance;
215 + declare export type MeasureOnSuccessCallback = __MeasureOnSuccessCallback;
216 +}
217 +
218 // eslint-disable-next-line no-unused-vars
219 declare const RN$enableMicrotasksInReact: boolean;
220