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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 8 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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,

0 commit comments

Comments
 (0)