Skip to content

Commit 0a30722

Browse files
authored
Flow: complete types first migration (#25389)
This complete the "types first" migration and enables the config everywhere.
1 parent bcc0567 commit 0a30722

33 files changed

+133
-107
lines changed

packages/react-devtools-shared/src/node_modules/react-window/src/FixedSizeGrid.js

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-shared/src/node_modules/react-window/src/FixedSizeList.js

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-shared/src/node_modules/react-window/src/VariableSizeGrid.js

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-shared/src/node_modules/react-window/src/VariableSizeList.js

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-dom-bindings/src/client/ReactDOMInput.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function isControlled(props) {
5959
* See http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
6060
*/
6161

62-
export function getHostProps(element: Element, props: Object) {
62+
export function getHostProps(element: Element, props: Object): Object {
6363
const node = ((element: any): InputWithWrapperState);
6464
const checked = props.checked;
6565

packages/react-dom-bindings/src/client/ReactDOMSelect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function updateOptions(
134134
* selected.
135135
*/
136136

137-
export function getHostProps(element: Element, props: Object) {
137+
export function getHostProps(element: Element, props: Object): Object {
138138
return assign({}, props, {
139139
value: undefined,
140140
});

packages/react-dom-bindings/src/client/ReactDOMTextarea.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type TextAreaWithWrapperState = HTMLTextAreaElement & {
3737
* `defaultValue` if specified, or the children content (deprecated).
3838
*/
3939

40-
export function getHostProps(element: Element, props: Object) {
40+
export function getHostProps(element: Element, props: Object): Object {
4141
const node = ((element: any): TextAreaWithWrapperState);
4242

4343
if (props.dangerouslySetInnerHTML != null) {

packages/react-dom-bindings/src/client/setInnerHTML.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ let reusableSVGContainer;
2121
* @param {string} html
2222
* @internal
2323
*/
24-
const setInnerHTML = createMicrosoftUnsafeLocalFunction(function(
24+
const setInnerHTML: (
25+
node: Element,
26+
html: {valueOf(): {toString(): string, ...}, ...},
27+
) => void = createMicrosoftUnsafeLocalFunction(function(
2528
node: Element,
2629
html: {valueOf(): {toString(): string, ...}, ...},
2730
): void {

packages/react-dom-bindings/src/events/EventRegistry.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ if (enableCreateEventHandleAPI) {
2121
/**
2222
* Mapping from registration name to event name
2323
*/
24-
export const registrationNameDependencies = {};
24+
export const registrationNameDependencies: {
25+
[registrationName: string]: Array<DOMEventName>,
26+
} = {};
2527

2628
/**
2729
* Mapping from lowercase registration names to the properly cased version,
2830
* used to warn in the case of missing event handlers. Available
2931
* only in __DEV__.
3032
* @type {Object}
3133
*/
32-
export const possibleRegistrationNames = __DEV__ ? {} : (null: any);
34+
export const possibleRegistrationNames: {
35+
[lowerCasedName: string]: string,
36+
} = __DEV__ ? {} : (null: any);
3337
// Trust the developer to only use possibleRegistrationNames in __DEV__
3438

3539
export function registerTwoPhaseEvent(

packages/react-dom-bindings/src/events/ReactDOMEventListener.js

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

1010
import type {AnyNativeEvent} from '../events/PluginModuleType';
11-
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
11+
import type {Fiber, FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1212
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
1313
import type {DOMEventName} from '../events/DOMEventNames';
1414
import {enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay} from 'shared/ReactFeatureFlags';
@@ -58,15 +58,15 @@ import {isRootDehydrated} from 'react-reconciler/src/ReactFiberShellHydration';
5858
const {ReactCurrentBatchConfig} = ReactSharedInternals;
5959

6060
// TODO: can we stop exporting these?
61-
export let _enabled = true;
61+
export let _enabled: boolean = true;
6262

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

69-
export function isEnabled() {
69+
export function isEnabled(): boolean {
7070
return _enabled;
7171
}
7272

@@ -348,7 +348,7 @@ function dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEve
348348
);
349349
}
350350

351-
export let return_targetInst = null;
351+
export let return_targetInst: null | Fiber = null;
352352

353353
// Returns a SuspenseInstance or Container if it's blocked.
354354
// The return_targetInst field above is conceptually part of the return value.

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

+25-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import getEventCharCode from './getEventCharCode';
1616

1717
type EventInterfaceType = {
1818
[propName: string]: 0 | ((event: {[propName: string]: mixed, ...}) => mixed),
19-
...,
2019
};
2120

2221
function functionThatReturnsTrue() {
@@ -153,14 +152,16 @@ const EventInterface = {
153152
defaultPrevented: 0,
154153
isTrusted: 0,
155154
};
156-
export const SyntheticEvent = createSyntheticEvent(EventInterface);
155+
export const SyntheticEvent: $FlowFixMe = createSyntheticEvent(EventInterface);
157156

158157
const UIEventInterface: EventInterfaceType = {
159158
...EventInterface,
160159
view: 0,
161160
detail: 0,
162161
};
163-
export const SyntheticUIEvent = createSyntheticEvent(UIEventInterface);
162+
export const SyntheticUIEvent: $FlowFixMe = createSyntheticEvent(
163+
UIEventInterface,
164+
);
164165

165166
let lastMovementX;
166167
let lastMovementY;
@@ -225,7 +226,9 @@ const MouseEventInterface: EventInterfaceType = {
225226
return lastMovementY;
226227
},
227228
};
228-
export const SyntheticMouseEvent = createSyntheticEvent(MouseEventInterface);
229+
export const SyntheticMouseEvent: $FlowFixMe = createSyntheticEvent(
230+
MouseEventInterface,
231+
);
229232

230233
/**
231234
* @interface DragEvent
@@ -235,7 +238,9 @@ const DragEventInterface: EventInterfaceType = {
235238
...MouseEventInterface,
236239
dataTransfer: 0,
237240
};
238-
export const SyntheticDragEvent = createSyntheticEvent(DragEventInterface);
241+
export const SyntheticDragEvent: $FlowFixMe = createSyntheticEvent(
242+
DragEventInterface,
243+
);
239244

240245
/**
241246
* @interface FocusEvent
@@ -245,7 +250,9 @@ const FocusEventInterface: EventInterfaceType = {
245250
...UIEventInterface,
246251
relatedTarget: 0,
247252
};
248-
export const SyntheticFocusEvent = createSyntheticEvent(FocusEventInterface);
253+
export const SyntheticFocusEvent: $FlowFixMe = createSyntheticEvent(
254+
FocusEventInterface,
255+
);
249256

250257
/**
251258
* @interface Event
@@ -258,7 +265,7 @@ const AnimationEventInterface: EventInterfaceType = {
258265
elapsedTime: 0,
259266
pseudoElement: 0,
260267
};
261-
export const SyntheticAnimationEvent = createSyntheticEvent(
268+
export const SyntheticAnimationEvent: $FlowFixMe = createSyntheticEvent(
262269
AnimationEventInterface,
263270
);
264271

@@ -274,7 +281,7 @@ const ClipboardEventInterface: EventInterfaceType = {
274281
: window.clipboardData;
275282
},
276283
};
277-
export const SyntheticClipboardEvent = createSyntheticEvent(
284+
export const SyntheticClipboardEvent: $FlowFixMe = createSyntheticEvent(
278285
ClipboardEventInterface,
279286
);
280287

@@ -286,7 +293,7 @@ const CompositionEventInterface: EventInterfaceType = {
286293
...EventInterface,
287294
data: 0,
288295
};
289-
export const SyntheticCompositionEvent = createSyntheticEvent(
296+
export const SyntheticCompositionEvent: $FlowFixMe = createSyntheticEvent(
290297
CompositionEventInterface,
291298
);
292299

@@ -487,7 +494,7 @@ const KeyboardEventInterface = {
487494
return 0;
488495
},
489496
};
490-
export const SyntheticKeyboardEvent = createSyntheticEvent(
497+
export const SyntheticKeyboardEvent: $FlowFixMe = createSyntheticEvent(
491498
KeyboardEventInterface,
492499
);
493500

@@ -508,7 +515,7 @@ const PointerEventInterface = {
508515
pointerType: 0,
509516
isPrimary: 0,
510517
};
511-
export const SyntheticPointerEvent = createSyntheticEvent(
518+
export const SyntheticPointerEvent: $FlowFixMe = createSyntheticEvent(
512519
PointerEventInterface,
513520
);
514521

@@ -527,7 +534,9 @@ const TouchEventInterface = {
527534
shiftKey: 0,
528535
getModifierState: getEventModifierState,
529536
};
530-
export const SyntheticTouchEvent = createSyntheticEvent(TouchEventInterface);
537+
export const SyntheticTouchEvent: $FlowFixMe = createSyntheticEvent(
538+
TouchEventInterface,
539+
);
531540

532541
/**
533542
* @interface Event
@@ -540,7 +549,7 @@ const TransitionEventInterface = {
540549
elapsedTime: 0,
541550
pseudoElement: 0,
542551
};
543-
export const SyntheticTransitionEvent = createSyntheticEvent(
552+
export const SyntheticTransitionEvent: $FlowFixMe = createSyntheticEvent(
544553
TransitionEventInterface,
545554
);
546555

@@ -580,4 +589,6 @@ const WheelEventInterface = {
580589
// ~40 pixels, for DOM_DELTA_SCREEN (2) it is 87.5% of viewport size.
581590
deltaMode: 0,
582591
};
583-
export const SyntheticWheelEvent = createSyntheticEvent(WheelEventInterface);
592+
export const SyntheticWheelEvent: $FlowFixMe = createSyntheticEvent(
593+
WheelEventInterface,
594+
);

packages/react-dom-bindings/src/events/forks/EventListener-www.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ export function addEventBubbleListener(
1616
target: EventTarget,
1717
eventType: string,
1818
listener: Function,
19-
) {
19+
): mixed {
2020
return EventListenerWWW.listen(target, eventType, listener);
2121
}
2222

2323
export function addEventCaptureListener(
2424
target: EventTarget,
2525
eventType: string,
2626
listener: Function,
27-
) {
27+
): mixed {
2828
return EventListenerWWW.capture(target, eventType, listener);
2929
}
3030

@@ -33,7 +33,7 @@ export function addEventCaptureListenerWithPassiveFlag(
3333
eventType: string,
3434
listener: Function,
3535
passive: boolean,
36-
) {
36+
): mixed {
3737
return EventListenerWWW.captureWithPassiveFlag(
3838
target,
3939
eventType,
@@ -47,7 +47,7 @@ export function addEventBubbleListenerWithPassiveFlag(
4747
eventType: string,
4848
listener: Function,
4949
passive: boolean,
50-
) {
50+
): mixed {
5151
return EventListenerWWW.bubbleWithPassiveFlag(
5252
target,
5353
eventType,

packages/react-dom/src/client/ReactDOM.js

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

1010
import type {ReactNodeList} from 'shared/ReactTypes';
11-
import type {Container} from 'react-dom-bindings/src/client/ReactDOMHostConfig';
11+
import type {
12+
Container,
13+
PublicInstance,
14+
} from 'react-dom-bindings/src/client/ReactDOMHostConfig';
1215
import type {
1316
RootType,
1417
HydrateRootOptions,
@@ -125,7 +128,7 @@ function renderSubtreeIntoContainer(
125128
element: React$Element<any>,
126129
containerNode: Container,
127130
callback: ?Function,
128-
) {
131+
): React$Component<any, any> | PublicInstance | null {
129132
return unstable_renderSubtreeIntoContainer(
130133
parentComponent,
131134
element,
@@ -171,7 +174,7 @@ declare function flushSync<R>(fn: () => R): R;
171174
// eslint-disable-next-line no-redeclare
172175
declare function flushSync(): void;
173176
// eslint-disable-next-line no-redeclare
174-
function flushSync(fn) {
177+
function flushSync<R>(fn: (() => R) | void): R | void {
175178
if (__DEV__) {
176179
if (isAlreadyRendering()) {
177180
console.error(

0 commit comments

Comments
 (0)