Skip to content

Commit 3a35171

Browse files
committed
Flow: fix Fiber typed as any
1 parent c739cef commit 3a35171

20 files changed

+50
-18
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: 5 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,8 @@ 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+
const leave: KnownReactSyntheticEvent = new SyntheticEventCtor(
137139
leaveEventType,
138140
eventTypePrefix + 'leave',
139141
from,
@@ -149,6 +151,7 @@ function extractEvents(
149151
// the first ancestor. Next time, we will ignore the event.
150152
const nativeTargetInst = getClosestInstanceFromNode((nativeEventTarget: any));
151153
if (nativeTargetInst === targetInst) {
154+
// $FlowFixMe[prop-missing]
152155
const enterEvent: KnownReactSyntheticEvent = new SyntheticEventCtor(
153156
enterEventType,
154157
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-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,

packages/react-reconciler/src/ReactFiberConcurrentUpdates.old.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,

packages/react-reconciler/src/ReactFiberLane.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 {Transition} from './ReactFiberTracingMarkerComponent.new';
1212
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates.new';
1313

packages/react-reconciler/src/ReactFiberLane.old.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 {Transition} from './ReactFiberTracingMarkerComponent.old';
1212
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates.old';
1313

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

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

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

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

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

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

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

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import type {
1818
} from 'react-native-renderer/src/ReactNativeTypes';
1919
import type {RNTopLevelEventType} from 'react-native-renderer/src/legacy-events/TopLevelEventTypes';
2020
import type {CapturedError} from 'react-reconciler/src/ReactCapturedValue';
21-
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
21+
22+
// libdefs cannot actually import, this should be from
23+
// react-reconciler/src/ReactInternalTypes
24+
type __Fiber = any;
2225

2326
type DeepDifferOptions = {+unsafelyIgnoreFunctions?: boolean};
2427
type RawEventEmitterEvent = $ReadOnly<{
@@ -189,7 +192,7 @@ declare var nativeFabricUIManager: {
189192
node: Node,
190193
locationX: number,
191194
locationY: number,
192-
callback: (Fiber) => void,
195+
callback: (__Fiber) => void,
193196
) => void,
194197
setIsJSResponder: (
195198
node: Node,

0 commit comments

Comments
 (0)