Skip to content

Commit 9328988

Browse files
authored
Flow: fix Fiber typed as any (#25241)
1 parent c739cef commit 9328988

21 files changed

+73
-35
lines changed

packages/react-dom/src/events/SyntheticEvent.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
/* eslint valid-typeof: 0 */
1111

12+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
13+
1214
import assign from 'shared/assign';
1315
import getEventCharCode from './getEventCharCode';
1416

@@ -44,7 +46,7 @@ function createSyntheticEvent(Interface: EventInterfaceType) {
4446
function SyntheticBaseEvent(
4547
reactName: string | null,
4648
reactEventType: string,
47-
targetInst: Fiber,
49+
targetInst: Fiber | null,
4850
nativeEvent: {[propName: string]: mixed, ...},
4951
nativeEventTarget: null | EventTarget,
5052
) {

packages/react-dom/src/events/plugins/BeforeInputEventPlugin.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1212
import type {AnyNativeEvent} from '../../events/PluginModuleType';
1313
import type {DispatchQueue} from '../DOMPluginEventSystem';
1414
import type {EventSystemFlags} from '../EventSystemFlags';
15+
import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';
1516

1617
import {canUseDOM} from 'shared/ExecutionEnvironment';
1718

@@ -228,7 +229,8 @@ function extractCompositionEvent(
228229

229230
const listeners = accumulateTwoPhaseListeners(targetInst, eventType);
230231
if (listeners.length > 0) {
231-
const event = new SyntheticCompositionEvent(
232+
// $FlowFixMe[incompatible-type]
233+
const event: ReactSyntheticEvent = new SyntheticCompositionEvent(
232234
eventType,
233235
domEventName,
234236
null,
@@ -239,10 +241,12 @@ function extractCompositionEvent(
239241
if (fallbackData) {
240242
// Inject data generated from fallback path into the synthetic event.
241243
// This matches the property of native CompositionEventInterface.
244+
// $FlowFixMe[incompatible-use]
242245
event.data = fallbackData;
243246
} else {
244247
const customData = getDataFromCustomEvent(nativeEvent);
245248
if (customData !== null) {
249+
// $FlowFixMe[incompatible-use]
246250
event.data = customData;
247251
}
248252
}
@@ -398,14 +402,16 @@ function extractBeforeInputEvent(
398402

399403
const listeners = accumulateTwoPhaseListeners(targetInst, 'onBeforeInput');
400404
if (listeners.length > 0) {
401-
const event = new SyntheticInputEvent(
405+
// $FlowFixMe[incompatible-type]
406+
const event: ReactSyntheticEvent = new SyntheticInputEvent(
402407
'onBeforeInput',
403408
'beforeinput',
404409
null,
405410
nativeEvent,
406411
nativeEventTarget,
407412
);
408413
dispatchQueue.push({event, listeners});
414+
// $FlowFixMe[incompatible-use]
409415
event.data = chars;
410416
}
411417
}

packages/react-dom/src/events/plugins/ChangeEventPlugin.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import type {AnyNativeEvent} from '../PluginModuleType';
1010
import type {DOMEventName} from '../DOMEventNames';
1111
import type {DispatchQueue} from '../DOMPluginEventSystem';
1212
import type {EventSystemFlags} from '../EventSystemFlags';
13+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
14+
import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';
1315

1416
import {registerTwoPhaseEvent} from '../EventRegistry';
1517
import {SyntheticEvent} from '../SyntheticEvent';
@@ -57,7 +59,8 @@ function createAndAccumulateChangeEvent(
5759
enqueueStateRestore(((target: any): Node));
5860
const listeners = accumulateTwoPhaseListeners(inst, 'onChange');
5961
if (listeners.length > 0) {
60-
const event = new SyntheticEvent(
62+
// $FlowFixMe[incompatible-type]
63+
const event: ReactSyntheticEvent = new SyntheticEvent(
6164
'onChange',
6265
'change',
6366
null,

packages/react-dom/src/events/plugins/EnterLeaveEventPlugin.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type {AnyNativeEvent} from '../PluginModuleType';
1111
import type {DOMEventName} from '../DOMEventNames';
1212
import type {DispatchQueue} from '../DOMPluginEventSystem';
1313
import type {EventSystemFlags} from '../EventSystemFlags';
14+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
15+
import type {KnownReactSyntheticEvent} from '../ReactSyntheticEventType';
1416

1517
import {registerDirectEvent} from '../EventRegistry';
1618
import {isReplayingEvent} from '../CurrentReplayingEvent';
@@ -21,7 +23,6 @@ import {
2123
isContainerMarkedAsRoot,
2224
} from '../../client/ReactDOMComponentTree';
2325
import {accumulateEnterLeaveTwoPhaseListeners} from '../DOMPluginEventSystem';
24-
import type {KnownReactSyntheticEvent} from '../ReactSyntheticEventType';
2526

2627
import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags';
2728
import {getNearestMountedFiber} from 'react-reconciler/src/ReactFiberTreeReflection';
@@ -133,7 +134,9 @@ function extractEvents(
133134
const fromNode = from == null ? win : getNodeFromInstance(from);
134135
const toNode = to == null ? win : getNodeFromInstance(to);
135136

136-
const leave = new SyntheticEventCtor(
137+
// $FlowFixMe[prop-missing]
138+
// $FlowFixMe[incompatible-type]
139+
const leave: KnownReactSyntheticEvent = new SyntheticEventCtor(
137140
leaveEventType,
138141
eventTypePrefix + 'leave',
139142
from,
@@ -149,6 +152,7 @@ function extractEvents(
149152
// the first ancestor. Next time, we will ignore the event.
150153
const nativeTargetInst = getClosestInstanceFromNode((nativeEventTarget: any));
151154
if (nativeTargetInst === targetInst) {
155+
// $FlowFixMe[prop-missing]
152156
const enterEvent: KnownReactSyntheticEvent = new SyntheticEventCtor(
153157
enterEventType,
154158
eventTypePrefix + 'enter',

packages/react-dom/src/events/plugins/SelectEventPlugin.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type {AnyNativeEvent} from '../PluginModuleType';
1111
import type {DOMEventName} from '../DOMEventNames';
1212
import type {DispatchQueue} from '../DOMPluginEventSystem';
1313
import type {EventSystemFlags} from '../EventSystemFlags';
14+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
15+
import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';
1416

1517
import {canUseDOM} from 'shared/ExecutionEnvironment';
1618
import {SyntheticEvent} from '../../events/SyntheticEvent';
@@ -114,7 +116,8 @@ function constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget) {
114116
'onSelect',
115117
);
116118
if (listeners.length > 0) {
117-
const event = new SyntheticEvent(
119+
// $FlowFixMe[incompatible-type]
120+
const event: ReactSyntheticEvent = new SyntheticEvent(
118121
'onSelect',
119122
'select',
120123
null,

packages/react-dom/src/events/plugins/SimpleEventPlugin.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1212
import type {AnyNativeEvent} from '../../events/PluginModuleType';
1313
import type {DispatchQueue} from '../DOMPluginEventSystem';
1414
import type {EventSystemFlags} from '../EventSystemFlags';
15+
import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';
1516

1617
import {
1718
SyntheticEvent,
@@ -172,7 +173,8 @@ function extractEvents(
172173
);
173174
if (listeners.length > 0) {
174175
// Intentionally create event lazily.
175-
const event = new SyntheticEventCtor(
176+
// $FlowFixMe[incompatible-type]
177+
const event: ReactSyntheticEvent = new SyntheticEventCtor(
176178
reactName,
177179
reactEventType,
178180
null,
@@ -204,7 +206,8 @@ function extractEvents(
204206
);
205207
if (listeners.length > 0) {
206208
// Intentionally create event lazily.
207-
const event = new SyntheticEventCtor(
209+
// $FlowFixMe[incompatible-type]
210+
const event: ReactSyntheticEvent = new SyntheticEventCtor(
208211
reactName,
209212
reactEventType,
210213
null,

packages/react-native-renderer/src/ReactFabricEventEmitter.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import type {AnyNativeEvent} from './legacy-events/PluginModuleType';
1111
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1212
import type {LegacyPluginModule} from './legacy-events/PluginModuleType';
1313
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';
1518

1619
import {registrationNameModules} from './legacy-events/EventPluginRegistry';
1720
import {batchedUpdates} from './legacy-events/ReactGenericBatching';

packages/react-reconciler/src/ReactFiberCacheComponent.new.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import type {ReactContext} from 'shared/ReactTypes';
11+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1112

1213
import {enableCache} from 'shared/ReactFeatureFlags';
1314
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';

packages/react-reconciler/src/ReactFiberCacheComponent.old.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import type {ReactContext} from 'shared/ReactTypes';
11+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1112

1213
import {enableCache} from 'shared/ReactFeatureFlags';
1314
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';

packages/react-reconciler/src/ReactFiberConcurrentUpdates.new.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {FiberRoot} from './ReactInternalTypes';
10+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1111
import type {
1212
UpdateQueue as HookQueue,
1313
Update as HookUpdate,

packages/react-reconciler/src/ReactFiberConcurrentUpdates.old.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {FiberRoot} from './ReactInternalTypes';
10+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1111
import type {
1212
UpdateQueue as HookQueue,
1313
Update as HookUpdate,

packages/react-reconciler/src/ReactFiberLane.new.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {FiberRoot} from './ReactInternalTypes';
10+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1111
import type {Transition} from './ReactFiberTracingMarkerComponent.new';
1212
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates.new';
1313

packages/react-reconciler/src/ReactFiberLane.old.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {FiberRoot} from './ReactInternalTypes';
10+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1111
import type {Transition} from './ReactFiberTracingMarkerComponent.old';
1212
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates.old';
1313

packages/react-reconciler/src/ReactFiberTransition.new.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @flow
88
*/
9-
import type {FiberRoot} from './ReactInternalTypes';
9+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1010
import type {Lanes} from './ReactFiberLane.new';
1111
import type {StackCursor} from './ReactFiberStack.new';
1212
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.new';

packages/react-reconciler/src/ReactFiberTransition.old.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @flow
88
*/
9-
import type {FiberRoot} from './ReactInternalTypes';
9+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1010
import type {Lanes} from './ReactFiberLane.old';
1111
import type {StackCursor} from './ReactFiberStack.old';
1212
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.old';

packages/react-reconciler/src/ReactFiberTransitionPool.old.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @flow
88
*/
9-
import type {FiberRoot} from './ReactInternalTypes';
9+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1010
import type {Lanes} from './ReactFiberLane.old';
1111
import type {StackCursor} from './ReactFiberStack.old';
1212
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.old';

packages/react-reconciler/src/ReactFiberTreeContext.new.js

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
// log2(32) = 5 bits. That means we can lop bits off the end 5 at a time without
6161
// affecting the final result.
6262

63+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
64+
6365
import {getIsHydrating} from './ReactFiberHydrationContext.new';
6466
import {clz32} from './clz32';
6567
import {Forked, NoFlags} from './ReactFiberFlags';

packages/react-reconciler/src/ReactFiberTreeContext.old.js

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
// log2(32) = 5 bits. That means we can lop bits off the end 5 at a time without
6161
// affecting the final result.
6262

63+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
64+
6365
import {getIsHydrating} from './ReactFiberHydrationContext.old';
6466
import {clz32} from './clz32';
6567
import {Forked, NoFlags} from './ReactFiberFlags';

packages/react-reconciler/src/getComponentNameFromFiber.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import type {ReactContext, ReactProviderType} from 'shared/ReactTypes';
11+
import type {Fiber} from './ReactInternalTypes';
1112

1213
import {enableLegacyHidden} from 'shared/ReactFeatureFlags';
1314

packages/shared/ReactTypes.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @flow
88
*/
99

10+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
11+
1012
export type ReactNode =
1113
| React$Element<any>
1214
| ReactPortal

scripts/flow/react-native-host-hooks.js

+23-18
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99

1010
/* eslint-disable */
1111

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;
2227

2328
type DeepDifferOptions = {+unsafelyIgnoreFunctions?: boolean};
2429
type RawEventEmitterEvent = $ReadOnly<{
@@ -53,7 +58,7 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
5358
...
5459
};
5560
declare export var ReactFiberErrorDialog: {
56-
showErrorDialog: (error: CapturedError) => boolean,
61+
showErrorDialog: (error: __CapturedError) => boolean,
5762
...
5863
};
5964
declare export var Platform: {OS: string, ...};
@@ -130,8 +135,8 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
130135
customDirectEventTypes: Object,
131136
eventTypes: Object,
132137

133-
register: (name: string, callback: ViewConfigGetter) => string,
134-
get: (name: string) => ReactNativeBaseComponentViewConfig,
138+
register: (name: string, callback: __ViewConfigGetter) => string,
139+
get: (name: string) => __ReactNativeBaseComponentViewConfig,
135140
...
136141
};
137142
declare export var RawEventEmitter: {
@@ -166,30 +171,30 @@ declare var nativeFabricUIManager: {
166171
registerEventHandler: (
167172
callback: (
168173
eventTarget: null | Object,
169-
type: RNTopLevelEventType,
174+
type: __RNTopLevelEventType,
170175
payload: Object,
171176
) => void,
172177
) => void,
173178

174179
dispatchCommand: (node: Object, command: string, args: Array<any>) => void,
175180
sendAccessibilityEvent: (node: Object, eventTypeName: string) => void,
176181

177-
measure: (node: Node, callback: MeasureOnSuccessCallback) => void,
182+
measure: (node: Node, callback: __MeasureOnSuccessCallback) => void,
178183
measureInWindow: (
179184
node: Node,
180-
callback: MeasureInWindowOnSuccessCallback,
185+
callback: __MeasureInWindowOnSuccessCallback,
181186
) => void,
182187
measureLayout: (
183188
node: Node,
184189
relativeNode: Node,
185190
onFail: () => void,
186-
onSuccess: MeasureLayoutOnSuccessCallback,
191+
onSuccess: __MeasureLayoutOnSuccessCallback,
187192
) => void,
188193
findNodeAtPoint: (
189194
node: Node,
190195
locationX: number,
191196
locationY: number,
192-
callback: (Fiber) => void,
197+
callback: (Object) => void,
193198
) => void,
194199
setIsJSResponder: (
195200
node: Node,

0 commit comments

Comments
 (0)