Skip to content

Commit

Permalink
Flow: fix Fiber typed as any (#25241)
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens authored and rickhanlonii committed Oct 5, 2022
1 parent a8f914f commit 8b1ac40
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 35 deletions.
4 changes: 3 additions & 1 deletion packages/react-dom/src/events/SyntheticEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/* eslint valid-typeof: 0 */

import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';

import assign from 'shared/assign';
import getEventCharCode from './getEventCharCode';

Expand Down Expand Up @@ -44,7 +46,7 @@ function createSyntheticEvent(Interface: EventInterfaceType) {
function SyntheticBaseEvent(
reactName: string | null,
reactEventType: string,
targetInst: Fiber,
targetInst: Fiber | null,
nativeEvent: {[propName: string]: mixed, ...},
nativeEventTarget: null | EventTarget,
) {
Expand Down
10 changes: 8 additions & 2 deletions packages/react-dom/src/events/plugins/BeforeInputEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {AnyNativeEvent} from '../../events/PluginModuleType';
import type {DispatchQueue} from '../DOMPluginEventSystem';
import type {EventSystemFlags} from '../EventSystemFlags';
import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';

import {canUseDOM} from 'shared/ExecutionEnvironment';

Expand Down Expand Up @@ -228,7 +229,8 @@ function extractCompositionEvent(

const listeners = accumulateTwoPhaseListeners(targetInst, eventType);
if (listeners.length > 0) {
const event = new SyntheticCompositionEvent(
// $FlowFixMe[incompatible-type]
const event: ReactSyntheticEvent = new SyntheticCompositionEvent(
eventType,
domEventName,
null,
Expand All @@ -239,10 +241,12 @@ function extractCompositionEvent(
if (fallbackData) {
// Inject data generated from fallback path into the synthetic event.
// This matches the property of native CompositionEventInterface.
// $FlowFixMe[incompatible-use]
event.data = fallbackData;
} else {
const customData = getDataFromCustomEvent(nativeEvent);
if (customData !== null) {
// $FlowFixMe[incompatible-use]
event.data = customData;
}
}
Expand Down Expand Up @@ -398,14 +402,16 @@ function extractBeforeInputEvent(

const listeners = accumulateTwoPhaseListeners(targetInst, 'onBeforeInput');
if (listeners.length > 0) {
const event = new SyntheticInputEvent(
// $FlowFixMe[incompatible-type]
const event: ReactSyntheticEvent = new SyntheticInputEvent(
'onBeforeInput',
'beforeinput',
null,
nativeEvent,
nativeEventTarget,
);
dispatchQueue.push({event, listeners});
// $FlowFixMe[incompatible-use]
event.data = chars;
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/react-dom/src/events/plugins/ChangeEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import type {AnyNativeEvent} from '../PluginModuleType';
import type {DOMEventName} from '../DOMEventNames';
import type {DispatchQueue} from '../DOMPluginEventSystem';
import type {EventSystemFlags} from '../EventSystemFlags';
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';

import {registerTwoPhaseEvent} from '../EventRegistry';
import {SyntheticEvent} from '../SyntheticEvent';
Expand Down Expand Up @@ -57,7 +59,8 @@ function createAndAccumulateChangeEvent(
enqueueStateRestore(((target: any): Node));
const listeners = accumulateTwoPhaseListeners(inst, 'onChange');
if (listeners.length > 0) {
const event = new SyntheticEvent(
// $FlowFixMe[incompatible-type]
const event: ReactSyntheticEvent = new SyntheticEvent(
'onChange',
'change',
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {AnyNativeEvent} from '../PluginModuleType';
import type {DOMEventName} from '../DOMEventNames';
import type {DispatchQueue} from '../DOMPluginEventSystem';
import type {EventSystemFlags} from '../EventSystemFlags';
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {KnownReactSyntheticEvent} from '../ReactSyntheticEventType';

import {registerDirectEvent} from '../EventRegistry';
import {isReplayingEvent} from '../CurrentReplayingEvent';
Expand All @@ -21,7 +23,6 @@ import {
isContainerMarkedAsRoot,
} from '../../client/ReactDOMComponentTree';
import {accumulateEnterLeaveTwoPhaseListeners} from '../DOMPluginEventSystem';
import type {KnownReactSyntheticEvent} from '../ReactSyntheticEventType';

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

const leave = new SyntheticEventCtor(
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-type]
const leave: KnownReactSyntheticEvent = new SyntheticEventCtor(
leaveEventType,
eventTypePrefix + 'leave',
from,
Expand All @@ -149,6 +152,7 @@ function extractEvents(
// the first ancestor. Next time, we will ignore the event.
const nativeTargetInst = getClosestInstanceFromNode((nativeEventTarget: any));
if (nativeTargetInst === targetInst) {
// $FlowFixMe[prop-missing]
const enterEvent: KnownReactSyntheticEvent = new SyntheticEventCtor(
enterEventType,
eventTypePrefix + 'enter',
Expand Down
5 changes: 4 additions & 1 deletion packages/react-dom/src/events/plugins/SelectEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {AnyNativeEvent} from '../PluginModuleType';
import type {DOMEventName} from '../DOMEventNames';
import type {DispatchQueue} from '../DOMPluginEventSystem';
import type {EventSystemFlags} from '../EventSystemFlags';
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';

import {canUseDOM} from 'shared/ExecutionEnvironment';
import {SyntheticEvent} from '../../events/SyntheticEvent';
Expand Down Expand Up @@ -114,7 +116,8 @@ function constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget) {
'onSelect',
);
if (listeners.length > 0) {
const event = new SyntheticEvent(
// $FlowFixMe[incompatible-type]
const event: ReactSyntheticEvent = new SyntheticEvent(
'onSelect',
'select',
null,
Expand Down
7 changes: 5 additions & 2 deletions packages/react-dom/src/events/plugins/SimpleEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {AnyNativeEvent} from '../../events/PluginModuleType';
import type {DispatchQueue} from '../DOMPluginEventSystem';
import type {EventSystemFlags} from '../EventSystemFlags';
import type {ReactSyntheticEvent} from '../ReactSyntheticEventType';

import {
SyntheticEvent,
Expand Down Expand Up @@ -172,7 +173,8 @@ function extractEvents(
);
if (listeners.length > 0) {
// Intentionally create event lazily.
const event = new SyntheticEventCtor(
// $FlowFixMe[incompatible-type]
const event: ReactSyntheticEvent = new SyntheticEventCtor(
reactName,
reactEventType,
null,
Expand Down Expand Up @@ -204,7 +206,8 @@ function extractEvents(
);
if (listeners.length > 0) {
// Intentionally create event lazily.
const event = new SyntheticEventCtor(
// $FlowFixMe[incompatible-type]
const event: ReactSyntheticEvent = new SyntheticEventCtor(
reactName,
reactEventType,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type {AnyNativeEvent} from './legacy-events/PluginModuleType';
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {LegacyPluginModule} from './legacy-events/PluginModuleType';
import type {ReactSyntheticEvent} from './legacy-events/ReactSyntheticEventType';
import type {TopLevelType} from './legacy-events/TopLevelEventTypes';
import type {
RNTopLevelEventType,
TopLevelType,
} from './legacy-events/TopLevelEventTypes';

import {registrationNameModules} from './legacy-events/EventPluginRegistry';
import {batchedUpdates} from './legacy-events/ReactGenericBatching';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

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

import {enableCache} from 'shared/ReactFeatureFlags';
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

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

import {enableCache} from 'shared/ReactFeatureFlags';
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {FiberRoot} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {
UpdateQueue as HookQueue,
Update as HookUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {FiberRoot} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {
UpdateQueue as HookQueue,
Update as HookUpdate,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberLane.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {FiberRoot} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Transition} from './ReactFiberTracingMarkerComponent.new';
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates.new';

Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberLane.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {FiberRoot} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Transition} from './ReactFiberTracingMarkerComponent.old';
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates.old';

Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberTransition.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @flow
*/
import type {FiberRoot} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Lanes} from './ReactFiberLane.new';
import type {StackCursor} from './ReactFiberStack.new';
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.new';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberTransition.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @flow
*/
import type {FiberRoot} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Lanes} from './ReactFiberLane.old';
import type {StackCursor} from './ReactFiberStack.old';
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.old';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @flow
*/
import type {FiberRoot} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Lanes} from './ReactFiberLane.old';
import type {StackCursor} from './ReactFiberStack.old';
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.old';
Expand Down
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactFiberTreeContext.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
// log2(32) = 5 bits. That means we can lop bits off the end 5 at a time without
// affecting the final result.

import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';

import {getIsHydrating} from './ReactFiberHydrationContext.new';
import {clz32} from './clz32';
import {Forked, NoFlags} from './ReactFiberFlags';
Expand Down
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactFiberTreeContext.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
// log2(32) = 5 bits. That means we can lop bits off the end 5 at a time without
// affecting the final result.

import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';

import {getIsHydrating} from './ReactFiberHydrationContext.old';
import {clz32} from './clz32';
import {Forked, NoFlags} from './ReactFiberFlags';
Expand Down
1 change: 1 addition & 0 deletions packages/react-reconciler/src/getComponentNameFromFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

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

import {enableLegacyHidden} from 'shared/ReactFeatureFlags';

Expand Down
2 changes: 2 additions & 0 deletions packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @flow
*/

import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';

export type ReactNode =
| React$Element<any>
| ReactPortal
Expand Down
41 changes: 23 additions & 18 deletions scripts/flow/react-native-host-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@

/* eslint-disable */

import type {
MeasureOnSuccessCallback,
MeasureInWindowOnSuccessCallback,
MeasureLayoutOnSuccessCallback,
ReactNativeBaseComponentViewConfig,
ViewConfigGetter,
} from 'react-native-renderer/src/ReactNativeTypes';
import type {RNTopLevelEventType} from 'react-native-renderer/src/legacy-events/TopLevelEventTypes';
import type {CapturedError} from 'react-reconciler/src/ReactCapturedValue';
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
// libdefs cannot actually import. These are supposed to be the types imported
// from 'react-native-renderer/src/ReactNativeTypes'
type __MeasureOnSuccessCallback = any;
type __MeasureInWindowOnSuccessCallback = any;
type __MeasureLayoutOnSuccessCallback = any;
type __ReactNativeBaseComponentViewConfig = any;
type __ViewConfigGetter = any;

// libdefs cannot actually import. This is supposed to be the type imported
// from 'react-native-renderer/src/legacy-events/TopLevelEventTypes';
type __RNTopLevelEventType = any;

// libdefs cannot actually import. This is supposed to be the type imported
// from 'react-reconciler/src/ReactCapturedValue'
type __CapturedError = any;

type DeepDifferOptions = {+unsafelyIgnoreFunctions?: boolean};
type RawEventEmitterEvent = $ReadOnly<{
Expand Down Expand Up @@ -53,7 +58,7 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
...
};
declare export var ReactFiberErrorDialog: {
showErrorDialog: (error: CapturedError) => boolean,
showErrorDialog: (error: __CapturedError) => boolean,
...
};
declare export var Platform: {OS: string, ...};
Expand Down Expand Up @@ -130,8 +135,8 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
customDirectEventTypes: Object,
eventTypes: Object,

register: (name: string, callback: ViewConfigGetter) => string,
get: (name: string) => ReactNativeBaseComponentViewConfig,
register: (name: string, callback: __ViewConfigGetter) => string,
get: (name: string) => __ReactNativeBaseComponentViewConfig,
...
};
declare export var RawEventEmitter: {
Expand Down Expand Up @@ -166,30 +171,30 @@ declare var nativeFabricUIManager: {
registerEventHandler: (
callback: (
eventTarget: null | Object,
type: RNTopLevelEventType,
type: __RNTopLevelEventType,
payload: Object,
) => void,
) => void,

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

measure: (node: Node, callback: MeasureOnSuccessCallback) => void,
measure: (node: Node, callback: __MeasureOnSuccessCallback) => void,
measureInWindow: (
node: Node,
callback: MeasureInWindowOnSuccessCallback,
callback: __MeasureInWindowOnSuccessCallback,
) => void,
measureLayout: (
node: Node,
relativeNode: Node,
onFail: () => void,
onSuccess: MeasureLayoutOnSuccessCallback,
onSuccess: __MeasureLayoutOnSuccessCallback,
) => void,
findNodeAtPoint: (
node: Node,
locationX: number,
locationY: number,
callback: (Fiber) => void,
callback: (Object) => void,
) => void,
setIsJSResponder: (
node: Node,
Expand Down

0 comments on commit 8b1ac40

Please sign in to comment.