Flow: fix Fiber typed as any (#25241)
Jan Kassens committed
Sep 12, 2022 at 13:44 UTC
9328988c024800de05dfab70e55cfd0999445d8a
21 files changed
+73
-35
packages/react-dom/src/events/SyntheticEvent.js
+3
-1
@@ -9,6 +9,8 @@
9
10
/* eslint valid-typeof: 0 */
11
12
+import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
13
+
14
import assign from 'shared/assign';
15
import getEventCharCode from './getEventCharCode';
16
@@ -44,7 +46,7 @@ function createSyntheticEvent(Interface: EventInterfaceType) {
46
function SyntheticBaseEvent(
47
reactName: string | null,
48
reactEventType: string,
47
- targetInst: Fiber,
49
+ targetInst: Fiber | null,
50
nativeEvent: {[propName: string]: mixed, ...},
51
nativeEventTarget: null | EventTarget,
52
) {
packages/react-dom/src/events/plugins/BeforeInputEventPlugin.js
+8
-2
@@ -12,6 +12,7 @@ import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
12
import type {AnyNativeEvent} from '../../events/PluginModuleType';
13
import type {DispatchQueue} from '../DOMPluginEventSystem';
14
import type {EventSystemFlags} from '../EventSystemFlags';
15
+import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';
16
17
import {canUseDOM} from 'shared/ExecutionEnvironment';
18
@@ -228,7 +229,8 @@ function extractCompositionEvent(
229
230
const listeners = accumulateTwoPhaseListeners(targetInst, eventType);
231
if (listeners.length > 0) {
231
- const event = new SyntheticCompositionEvent(
232
+ // $FlowFixMe[incompatible-type]
233
+ const event: ReactSyntheticEvent = new SyntheticCompositionEvent(
234
eventType,
235
domEventName,
236
null,
@@ -239,10 +241,12 @@ function extractCompositionEvent(
241
if (fallbackData) {
242
// Inject data generated from fallback path into the synthetic event.
243
// This matches the property of native CompositionEventInterface.
244
+ // $FlowFixMe[incompatible-use]
245
event.data = fallbackData;
246
} else {
247
const customData = getDataFromCustomEvent(nativeEvent);
248
if (customData !== null) {
249
+ // $FlowFixMe[incompatible-use]
250
event.data = customData;
251
}
252
}
@@ -398,7 +402,8 @@ function extractBeforeInputEvent(
402
403
const listeners = accumulateTwoPhaseListeners(targetInst, 'onBeforeInput');
404
if (listeners.length > 0) {
401
- const event = new SyntheticInputEvent(
405
+ // $FlowFixMe[incompatible-type]
406
+ const event: ReactSyntheticEvent = new SyntheticInputEvent(
407
'onBeforeInput',
408
'beforeinput',
409
null,
@@ -406,6 +411,7 @@ function extractBeforeInputEvent(
411
nativeEventTarget,
412
);
413
dispatchQueue.push({event, listeners});
414
+ // $FlowFixMe[incompatible-use]
415
event.data = chars;
416
}
417
}
packages/react-dom/src/events/plugins/ChangeEventPlugin.js
+4
-1
@@ -10,6 +10,8 @@ import type {AnyNativeEvent} from '../PluginModuleType';
10
import type {DOMEventName} from '../DOMEventNames';
11
import type {DispatchQueue} from '../DOMPluginEventSystem';
12
import type {EventSystemFlags} from '../EventSystemFlags';
13
+import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
14
+import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';
15
16
import {registerTwoPhaseEvent} from '../EventRegistry';
17
import {SyntheticEvent} from '../SyntheticEvent';
@@ -57,7 +59,8 @@ function createAndAccumulateChangeEvent(
59
enqueueStateRestore(((target: any): Node));
60
const listeners = accumulateTwoPhaseListeners(inst, 'onChange');
61
if (listeners.length > 0) {
60
- const event = new SyntheticEvent(
62
+ // $FlowFixMe[incompatible-type]
63
+ const event: ReactSyntheticEvent = new SyntheticEvent(
64
'onChange',
65
'change',
66
null,
packages/react-dom/src/events/plugins/EnterLeaveEventPlugin.js
+6
-2
@@ -11,6 +11,8 @@ import type {AnyNativeEvent} from '../PluginModuleType';
11
import type {DOMEventName} from '../DOMEventNames';
12
import type {DispatchQueue} from '../DOMPluginEventSystem';
13
import type {EventSystemFlags} from '../EventSystemFlags';
14
+import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
15
+import type {KnownReactSyntheticEvent} from '../ReactSyntheticEventType';
16
17
import {registerDirectEvent} from '../EventRegistry';
18
import {isReplayingEvent} from '../CurrentReplayingEvent';
@@ -21,7 +23,6 @@ import {
23
isContainerMarkedAsRoot,
24
} from '../../client/ReactDOMComponentTree';
25
import {accumulateEnterLeaveTwoPhaseListeners} from '../DOMPluginEventSystem';
24
-import type {KnownReactSyntheticEvent} from '../ReactSyntheticEventType';
26
27
import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags';
28
import {getNearestMountedFiber} from 'react-reconciler/src/ReactFiberTreeReflection';
@@ -133,7 +134,9 @@ function extractEvents(
134
const fromNode = from == null ? win : getNodeFromInstance(from);
135
const toNode = to == null ? win : getNodeFromInstance(to);
136
136
- const leave = new SyntheticEventCtor(
137
+ // $FlowFixMe[prop-missing]
138
+ // $FlowFixMe[incompatible-type]
139
+ const leave: KnownReactSyntheticEvent = new SyntheticEventCtor(
140
leaveEventType,
141
eventTypePrefix + 'leave',
142
from,
@@ -149,6 +152,7 @@ function extractEvents(
152
// the first ancestor. Next time, we will ignore the event.
153
const nativeTargetInst = getClosestInstanceFromNode((nativeEventTarget: any));
154
if (nativeTargetInst === targetInst) {
155
+ // $FlowFixMe[prop-missing]
156
const enterEvent: KnownReactSyntheticEvent = new SyntheticEventCtor(
157
enterEventType,
158
eventTypePrefix + 'enter',
packages/react-dom/src/events/plugins/SelectEventPlugin.js
+4
-1
@@ -11,6 +11,8 @@ import type {AnyNativeEvent} from '../PluginModuleType';
11
import type {DOMEventName} from '../DOMEventNames';
12
import type {DispatchQueue} from '../DOMPluginEventSystem';
13
import type {EventSystemFlags} from '../EventSystemFlags';
14
+import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
15
+import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';
16
17
import {canUseDOM} from 'shared/ExecutionEnvironment';
18
import {SyntheticEvent} from '../../events/SyntheticEvent';
@@ -114,7 +116,8 @@ function constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget) {
116
'onSelect',
117
);
118
if (listeners.length > 0) {
117
- const event = new SyntheticEvent(
119
+ // $FlowFixMe[incompatible-type]
120
+ const event: ReactSyntheticEvent = new SyntheticEvent(
121
'onSelect',
122
'select',
123
null,
packages/react-dom/src/events/plugins/SimpleEventPlugin.js
+5
-2
@@ -12,6 +12,7 @@ import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
12
import type {AnyNativeEvent} from '../../events/PluginModuleType';
13
import type {DispatchQueue} from '../DOMPluginEventSystem';
14
import type {EventSystemFlags} from '../EventSystemFlags';
15
+import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';
16
17
import {
18
SyntheticEvent,
@@ -172,7 +173,8 @@ function extractEvents(
173
);
174
if (listeners.length > 0) {
175
// Intentionally create event lazily.
175
- const event = new SyntheticEventCtor(
176
+ // $FlowFixMe[incompatible-type]
177
+ const event: ReactSyntheticEvent = new SyntheticEventCtor(
178
reactName,
179
reactEventType,
180
null,
@@ -204,7 +206,8 @@ function extractEvents(
206
);
207
if (listeners.length > 0) {
208
// Intentionally create event lazily.
207
- const event = new SyntheticEventCtor(
209
+ // $FlowFixMe[incompatible-type]
210
+ const event: ReactSyntheticEvent = new SyntheticEventCtor(
211
reactName,
212
reactEventType,
213
null,
packages/react-native-renderer/src/ReactFabricEventEmitter.js
+4
-1
@@ -11,7 +11,10 @@ import type {AnyNativeEvent} from './legacy-events/PluginModuleType';
11
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
12
import type {LegacyPluginModule} from './legacy-events/PluginModuleType';
13
import type {ReactSyntheticEvent} from './legacy-events/ReactSyntheticEventType';
14
-import type {TopLevelType} from './legacy-events/TopLevelEventTypes';
14
+import type {
15
+ RNTopLevelEventType,
16
+ TopLevelType,
17
+} from './legacy-events/TopLevelEventTypes';
18
19
import {registrationNameModules} from './legacy-events/EventPluginRegistry';
20
import {batchedUpdates} from './legacy-events/ReactGenericBatching';
packages/react-reconciler/src/ReactFiberCacheComponent.new.js
+1
@@ -8,6 +8,7 @@
8
*/
9
10
import type {ReactContext} from 'shared/ReactTypes';
11
+import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
12
13
import {enableCache} from 'shared/ReactFeatureFlags';
14
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
packages/react-reconciler/src/ReactFiberCacheComponent.old.js
+1
@@ -8,6 +8,7 @@
8
*/
9
10
import type {ReactContext} from 'shared/ReactTypes';
11
+import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
12
13
import {enableCache} from 'shared/ReactFeatureFlags';
14
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
packages/react-reconciler/src/ReactFiberConcurrentUpdates.new.js
+1
-1
@@ -7,7 +7,7 @@
7
* @flow
8
*/
9
10
-import type {FiberRoot} from './ReactInternalTypes';
10
+import type {Fiber, FiberRoot} from './ReactInternalTypes';
11
import type {
12
UpdateQueue as HookQueue,
13
Update as HookUpdate,
packages/react-reconciler/src/ReactFiberConcurrentUpdates.old.js
+1
-1
@@ -7,7 +7,7 @@
7
* @flow
8
*/
9
10
-import type {FiberRoot} from './ReactInternalTypes';
10
+import type {Fiber, FiberRoot} from './ReactInternalTypes';
11
import type {
12
UpdateQueue as HookQueue,
13
Update as HookUpdate,
packages/react-reconciler/src/ReactFiberLane.new.js
+1
-1
@@ -7,7 +7,7 @@
7
* @flow
8
*/
9
10
-import type {FiberRoot} from './ReactInternalTypes';
10
+import type {Fiber, FiberRoot} from './ReactInternalTypes';
11
import type {Transition} from './ReactFiberTracingMarkerComponent.new';
12
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates.new';
13
packages/react-reconciler/src/ReactFiberLane.old.js
+1
-1
@@ -7,7 +7,7 @@
7
* @flow
8
*/
9
10
-import type {FiberRoot} from './ReactInternalTypes';
10
+import type {Fiber, FiberRoot} from './ReactInternalTypes';
11
import type {Transition} from './ReactFiberTracingMarkerComponent.old';
12
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates.old';
13
packages/react-reconciler/src/ReactFiberTransition.new.js
+1
-1
@@ -6,7 +6,7 @@
6
*
7
* @flow
8
*/
9
-import type {FiberRoot} from './ReactInternalTypes';
9
+import type {Fiber, FiberRoot} from './ReactInternalTypes';
10
import type {Lanes} from './ReactFiberLane.new';
11
import type {StackCursor} from './ReactFiberStack.new';
12
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.new';
packages/react-reconciler/src/ReactFiberTransition.old.js
+1
-1
@@ -6,7 +6,7 @@
6
*
7
* @flow
8
*/
9
-import type {FiberRoot} from './ReactInternalTypes';
9
+import type {Fiber, FiberRoot} from './ReactInternalTypes';
10
import type {Lanes} from './ReactFiberLane.old';
11
import type {StackCursor} from './ReactFiberStack.old';
12
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.old';
packages/react-reconciler/src/ReactFiberTransitionPool.old.js
+1
-1
@@ -6,7 +6,7 @@
6
*
7
* @flow
8
*/
9
-import type {FiberRoot} from './ReactInternalTypes';
9
+import type {Fiber, FiberRoot} from './ReactInternalTypes';
10
import type {Lanes} from './ReactFiberLane.old';
11
import type {StackCursor} from './ReactFiberStack.old';
12
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.old';
packages/react-reconciler/src/ReactFiberTreeContext.new.js
+2
@@ -60,6 +60,8 @@
60
// log2(32) = 5 bits. That means we can lop bits off the end 5 at a time without
61
// affecting the final result.
62
63
+import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
64
+
65
import {getIsHydrating} from './ReactFiberHydrationContext.new';
66
import {clz32} from './clz32';
67
import {Forked, NoFlags} from './ReactFiberFlags';
packages/react-reconciler/src/ReactFiberTreeContext.old.js
+2
@@ -60,6 +60,8 @@
60
// log2(32) = 5 bits. That means we can lop bits off the end 5 at a time without
61
// affecting the final result.
62
63
+import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
64
+
65
import {getIsHydrating} from './ReactFiberHydrationContext.old';
66
import {clz32} from './clz32';
67
import {Forked, NoFlags} from './ReactFiberFlags';
packages/react-reconciler/src/getComponentNameFromFiber.js
+1
@@ -8,6 +8,7 @@
8
*/
9
10
import type {ReactContext, ReactProviderType} from 'shared/ReactTypes';
11
+import type {Fiber} from './ReactInternalTypes';
12
13
import {enableLegacyHidden} from 'shared/ReactFeatureFlags';
14
packages/shared/ReactTypes.js
+2
@@ -7,6 +7,8 @@
7
* @flow
8
*/
9
10
+import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
11
+
12
export type ReactNode =
13
| React$Element<any>
14
| ReactPortal
scripts/flow/react-native-host-hooks.js
+23
-18
@@ -9,16 +9,21 @@
9
10
/* eslint-disable */
11
12
-import type {
13
- MeasureOnSuccessCallback,
14
- MeasureInWindowOnSuccessCallback,
15
- MeasureLayoutOnSuccessCallback,
16
- ReactNativeBaseComponentViewConfig,
17
- ViewConfigGetter,
18
-} from 'react-native-renderer/src/ReactNativeTypes';
19
-import type {RNTopLevelEventType} from 'react-native-renderer/src/legacy-events/TopLevelEventTypes';
20
-import type {CapturedError} from 'react-reconciler/src/ReactCapturedValue';
21
-import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
12
+// libdefs cannot actually import. These are supposed to be the types imported
13
+// from 'react-native-renderer/src/ReactNativeTypes'
14
+type __MeasureOnSuccessCallback = any;
15
+type __MeasureInWindowOnSuccessCallback = any;
16
+type __MeasureLayoutOnSuccessCallback = any;
17
+type __ReactNativeBaseComponentViewConfig = any;
18
+type __ViewConfigGetter = any;
19
+
20
+// libdefs cannot actually import. This is supposed to be the type imported
21
+// from 'react-native-renderer/src/legacy-events/TopLevelEventTypes';
22
+type __RNTopLevelEventType = any;
23
+
24
+// libdefs cannot actually import. This is supposed to be the type imported
25
+// from 'react-reconciler/src/ReactCapturedValue'
26
+type __CapturedError = any;
27
28
type DeepDifferOptions = {+unsafelyIgnoreFunctions?: boolean};
29
type RawEventEmitterEvent = $ReadOnly<{
@@ -53,7 +58,7 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
58
...
59
};
60
declare export var ReactFiberErrorDialog: {
56
- showErrorDialog: (error: CapturedError) => boolean,
61
+ showErrorDialog: (error: __CapturedError) => boolean,
62
...
63
};
64
declare export var Platform: {OS: string, ...};
@@ -130,8 +135,8 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
135
customDirectEventTypes: Object,
136
eventTypes: Object,
137
133
- register: (name: string, callback: ViewConfigGetter) => string,
134
- get: (name: string) => ReactNativeBaseComponentViewConfig,
138
+ register: (name: string, callback: __ViewConfigGetter) => string,
139
+ get: (name: string) => __ReactNativeBaseComponentViewConfig,
140
...
141
};
142
declare export var RawEventEmitter: {
@@ -166,7 +171,7 @@ declare var nativeFabricUIManager: {
171
registerEventHandler: (
172
callback: (
173
eventTarget: null | Object,
169
- type: RNTopLevelEventType,
174
+ type: __RNTopLevelEventType,
175
payload: Object,
176
) => void,
177
) => void,
@@ -174,22 +179,22 @@ declare var nativeFabricUIManager: {
179
dispatchCommand: (node: Object, command: string, args: Array<any>) => void,
180
sendAccessibilityEvent: (node: Object, eventTypeName: string) => void,
181
177
- measure: (node: Node, callback: MeasureOnSuccessCallback) => void,
182
+ measure: (node: Node, callback: __MeasureOnSuccessCallback) => void,
183
measureInWindow: (
184
node: Node,
180
- callback: MeasureInWindowOnSuccessCallback,
185
+ callback: __MeasureInWindowOnSuccessCallback,
186
) => void,
187
measureLayout: (
188
node: Node,
189
relativeNode: Node,
190
onFail: () => void,
186
- onSuccess: MeasureLayoutOnSuccessCallback,
191
+ onSuccess: __MeasureLayoutOnSuccessCallback,
192
) => void,
193
findNodeAtPoint: (
194
node: Node,
195
locationX: number,
196
locationY: number,
192
- callback: (Fiber) => void,
197
+ callback: (Object) => void,
198
) => void,
199
setIsJSResponder: (
200
node: Node,