Skip to content

Commit

Permalink
Flow: complete types first migration (#25389)
Browse files Browse the repository at this point in the history
This complete the "types first" migration and enables the config everywhere.
  • Loading branch information
kassens authored Oct 4, 2022
1 parent bcc0567 commit 0a30722
Show file tree
Hide file tree
Showing 33 changed files with 133 additions and 107 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/react-dom-bindings/src/client/ReactDOMInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function isControlled(props) {
* See http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
*/

export function getHostProps(element: Element, props: Object) {
export function getHostProps(element: Element, props: Object): Object {
const node = ((element: any): InputWithWrapperState);
const checked = props.checked;

Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom-bindings/src/client/ReactDOMSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function updateOptions(
* selected.
*/

export function getHostProps(element: Element, props: Object) {
export function getHostProps(element: Element, props: Object): Object {
return assign({}, props, {
value: undefined,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom-bindings/src/client/ReactDOMTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type TextAreaWithWrapperState = HTMLTextAreaElement & {
* `defaultValue` if specified, or the children content (deprecated).
*/

export function getHostProps(element: Element, props: Object) {
export function getHostProps(element: Element, props: Object): Object {
const node = ((element: any): TextAreaWithWrapperState);

if (props.dangerouslySetInnerHTML != null) {
Expand Down
5 changes: 4 additions & 1 deletion packages/react-dom-bindings/src/client/setInnerHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ let reusableSVGContainer;
* @param {string} html
* @internal
*/
const setInnerHTML = createMicrosoftUnsafeLocalFunction(function(
const setInnerHTML: (
node: Element,
html: {valueOf(): {toString(): string, ...}, ...},
) => void = createMicrosoftUnsafeLocalFunction(function(
node: Element,
html: {valueOf(): {toString(): string, ...}, ...},
): void {
Expand Down
8 changes: 6 additions & 2 deletions packages/react-dom-bindings/src/events/EventRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ if (enableCreateEventHandleAPI) {
/**
* Mapping from registration name to event name
*/
export const registrationNameDependencies = {};
export const registrationNameDependencies: {
[registrationName: string]: Array<DOMEventName>,
} = {};

/**
* Mapping from lowercase registration names to the properly cased version,
* used to warn in the case of missing event handlers. Available
* only in __DEV__.
* @type {Object}
*/
export const possibleRegistrationNames = __DEV__ ? {} : (null: any);
export const possibleRegistrationNames: {
[lowerCasedName: string]: string,
} = __DEV__ ? {} : (null: any);
// Trust the developer to only use possibleRegistrationNames in __DEV__

export function registerTwoPhaseEvent(
Expand Down
10 changes: 5 additions & 5 deletions packages/react-dom-bindings/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type {AnyNativeEvent} from '../events/PluginModuleType';
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
import type {Fiber, FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
import type {DOMEventName} from '../events/DOMEventNames';
import {enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay} from 'shared/ReactFeatureFlags';
Expand Down Expand Up @@ -58,15 +58,15 @@ import {isRootDehydrated} from 'react-reconciler/src/ReactFiberShellHydration';
const {ReactCurrentBatchConfig} = ReactSharedInternals;

// TODO: can we stop exporting these?
export let _enabled = true;
export let _enabled: boolean = true;

// This is exported in FB builds for use by legacy FB layer infra.
// We'd like to remove this but it's not clear if this is safe.
export function setEnabled(enabled: ?boolean) {
export function setEnabled(enabled: ?boolean): void {
_enabled = !!enabled;
}

export function isEnabled() {
export function isEnabled(): boolean {
return _enabled;
}

Expand Down Expand Up @@ -348,7 +348,7 @@ function dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEve
);
}

export let return_targetInst = null;
export let return_targetInst: null | Fiber = null;

// Returns a SuspenseInstance or Container if it's blocked.
// The return_targetInst field above is conceptually part of the return value.
Expand Down
39 changes: 25 additions & 14 deletions packages/react-dom-bindings/src/events/SyntheticEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import getEventCharCode from './getEventCharCode';

type EventInterfaceType = {
[propName: string]: 0 | ((event: {[propName: string]: mixed, ...}) => mixed),
...,
};

function functionThatReturnsTrue() {
Expand Down Expand Up @@ -153,14 +152,16 @@ const EventInterface = {
defaultPrevented: 0,
isTrusted: 0,
};
export const SyntheticEvent = createSyntheticEvent(EventInterface);
export const SyntheticEvent: $FlowFixMe = createSyntheticEvent(EventInterface);

const UIEventInterface: EventInterfaceType = {
...EventInterface,
view: 0,
detail: 0,
};
export const SyntheticUIEvent = createSyntheticEvent(UIEventInterface);
export const SyntheticUIEvent: $FlowFixMe = createSyntheticEvent(
UIEventInterface,
);

let lastMovementX;
let lastMovementY;
Expand Down Expand Up @@ -225,7 +226,9 @@ const MouseEventInterface: EventInterfaceType = {
return lastMovementY;
},
};
export const SyntheticMouseEvent = createSyntheticEvent(MouseEventInterface);
export const SyntheticMouseEvent: $FlowFixMe = createSyntheticEvent(
MouseEventInterface,
);

/**
* @interface DragEvent
Expand All @@ -235,7 +238,9 @@ const DragEventInterface: EventInterfaceType = {
...MouseEventInterface,
dataTransfer: 0,
};
export const SyntheticDragEvent = createSyntheticEvent(DragEventInterface);
export const SyntheticDragEvent: $FlowFixMe = createSyntheticEvent(
DragEventInterface,
);

/**
* @interface FocusEvent
Expand All @@ -245,7 +250,9 @@ const FocusEventInterface: EventInterfaceType = {
...UIEventInterface,
relatedTarget: 0,
};
export const SyntheticFocusEvent = createSyntheticEvent(FocusEventInterface);
export const SyntheticFocusEvent: $FlowFixMe = createSyntheticEvent(
FocusEventInterface,
);

/**
* @interface Event
Expand All @@ -258,7 +265,7 @@ const AnimationEventInterface: EventInterfaceType = {
elapsedTime: 0,
pseudoElement: 0,
};
export const SyntheticAnimationEvent = createSyntheticEvent(
export const SyntheticAnimationEvent: $FlowFixMe = createSyntheticEvent(
AnimationEventInterface,
);

Expand All @@ -274,7 +281,7 @@ const ClipboardEventInterface: EventInterfaceType = {
: window.clipboardData;
},
};
export const SyntheticClipboardEvent = createSyntheticEvent(
export const SyntheticClipboardEvent: $FlowFixMe = createSyntheticEvent(
ClipboardEventInterface,
);

Expand All @@ -286,7 +293,7 @@ const CompositionEventInterface: EventInterfaceType = {
...EventInterface,
data: 0,
};
export const SyntheticCompositionEvent = createSyntheticEvent(
export const SyntheticCompositionEvent: $FlowFixMe = createSyntheticEvent(
CompositionEventInterface,
);

Expand Down Expand Up @@ -487,7 +494,7 @@ const KeyboardEventInterface = {
return 0;
},
};
export const SyntheticKeyboardEvent = createSyntheticEvent(
export const SyntheticKeyboardEvent: $FlowFixMe = createSyntheticEvent(
KeyboardEventInterface,
);

Expand All @@ -508,7 +515,7 @@ const PointerEventInterface = {
pointerType: 0,
isPrimary: 0,
};
export const SyntheticPointerEvent = createSyntheticEvent(
export const SyntheticPointerEvent: $FlowFixMe = createSyntheticEvent(
PointerEventInterface,
);

Expand All @@ -527,7 +534,9 @@ const TouchEventInterface = {
shiftKey: 0,
getModifierState: getEventModifierState,
};
export const SyntheticTouchEvent = createSyntheticEvent(TouchEventInterface);
export const SyntheticTouchEvent: $FlowFixMe = createSyntheticEvent(
TouchEventInterface,
);

/**
* @interface Event
Expand All @@ -540,7 +549,7 @@ const TransitionEventInterface = {
elapsedTime: 0,
pseudoElement: 0,
};
export const SyntheticTransitionEvent = createSyntheticEvent(
export const SyntheticTransitionEvent: $FlowFixMe = createSyntheticEvent(
TransitionEventInterface,
);

Expand Down Expand Up @@ -580,4 +589,6 @@ const WheelEventInterface = {
// ~40 pixels, for DOM_DELTA_SCREEN (2) it is 87.5% of viewport size.
deltaMode: 0,
};
export const SyntheticWheelEvent = createSyntheticEvent(WheelEventInterface);
export const SyntheticWheelEvent: $FlowFixMe = createSyntheticEvent(
WheelEventInterface,
);
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export function addEventBubbleListener(
target: EventTarget,
eventType: string,
listener: Function,
) {
): mixed {
return EventListenerWWW.listen(target, eventType, listener);
}

export function addEventCaptureListener(
target: EventTarget,
eventType: string,
listener: Function,
) {
): mixed {
return EventListenerWWW.capture(target, eventType, listener);
}

Expand All @@ -33,7 +33,7 @@ export function addEventCaptureListenerWithPassiveFlag(
eventType: string,
listener: Function,
passive: boolean,
) {
): mixed {
return EventListenerWWW.captureWithPassiveFlag(
target,
eventType,
Expand All @@ -47,7 +47,7 @@ export function addEventBubbleListenerWithPassiveFlag(
eventType: string,
listener: Function,
passive: boolean,
) {
): mixed {
return EventListenerWWW.bubbleWithPassiveFlag(
target,
eventType,
Expand Down
9 changes: 6 additions & 3 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
*/

import type {ReactNodeList} from 'shared/ReactTypes';
import type {Container} from 'react-dom-bindings/src/client/ReactDOMHostConfig';
import type {
Container,
PublicInstance,
} from 'react-dom-bindings/src/client/ReactDOMHostConfig';
import type {
RootType,
HydrateRootOptions,
Expand Down Expand Up @@ -125,7 +128,7 @@ function renderSubtreeIntoContainer(
element: React$Element<any>,
containerNode: Container,
callback: ?Function,
) {
): React$Component<any, any> | PublicInstance | null {
return unstable_renderSubtreeIntoContainer(
parentComponent,
element,
Expand Down Expand Up @@ -171,7 +174,7 @@ declare function flushSync<R>(fn: () => R): R;
// eslint-disable-next-line no-redeclare
declare function flushSync(): void;
// eslint-disable-next-line no-redeclare
function flushSync(fn) {
function flushSync<R>(fn: (() => R) | void): R | void {
if (__DEV__) {
if (isAlreadyRendering()) {
console.error(
Expand Down
Loading

0 comments on commit 0a30722

Please sign in to comment.