Skip to content

Commit 4049cfe

Browse files
authored
Update Flow to 0.273 (#34274)
This version introduces "Natural Inference" which requires a couple more type annotations to make Flow pass.
1 parent e67e3be commit 4049cfe

File tree

15 files changed

+40
-34
lines changed

15 files changed

+40
-34
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ module.exports = {
565565
BigInt: 'readonly',
566566
BigInt64Array: 'readonly',
567567
BigUint64Array: 'readonly',
568+
CacheType: 'readonly',
568569
Class: 'readonly',
569570
ClientRect: 'readonly',
570571
CopyInspectedElementPath: 'readonly',

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
7575
"fbjs-scripts": "^3.0.1",
7676
"filesize": "^6.0.1",
77-
"flow-bin": "^0.272",
78-
"flow-remove-types": "^2.272",
77+
"flow-bin": "^0.273",
78+
"flow-remove-types": "^2.273",
7979
"flow-typed": "^4.1.1",
8080
"glob": "^7.1.6",
8181
"glob-stream": "^6.1.0",

packages/react-devtools-shared/src/backend/fiber/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6705,7 +6705,7 @@ export function attach(
67056705
if (isMostRecentlyInspectedElement(id) && !forceFullData) {
67066706
if (!hasElementUpdatedSinceLastInspected) {
67076707
if (path !== null) {
6708-
let secondaryCategory = null;
6708+
let secondaryCategory: 'suspendedBy' | 'hooks' | null = null;
67096709
if (path[0] === 'hooks') {
67106710
secondaryCategory = 'hooks';
67116711
}

packages/react-devtools-shared/src/hookNamesCache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function loadHookNames(
103103

104104
let timeoutID: $FlowFixMe | null;
105105
let didTimeout = false;
106-
let status = 'unknown';
106+
let status: 'success' | 'error' | 'timeout' | 'unknown' = 'unknown';
107107
let resolvedHookNames: HookNames | null = null;
108108

109109
const wake = () => {

packages/react-devtools-shared/src/hooks/parseHookNames/loadSourceAndMetadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import type {FetchFileWithCaching} from 'react-devtools-shared/src/devtools/view
6464

6565
// Prefer a cached albeit stale response to reduce download time.
6666
// We wouldn't want to load/parse a newer version of the source (even if one existed).
67-
const FETCH_OPTIONS = {cache: 'force-cache'};
67+
const FETCH_OPTIONS = {cache: 'force-cache' as CacheType};
6868

6969
const MAX_SOURCE_LENGTH = 100_000_000;
7070

packages/react-devtools-timeline/src/import-worker/preprocessData.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ function processTimelineEvent(
509509
} else if (name.startsWith('--schedule-forced-update-')) {
510510
const [laneBitmaskString, componentName] = name.slice(25).split('-');
511511

512-
const forceUpdateEvent = {
512+
const forceUpdateEvent: SchedulingEvent = {
513513
type: 'schedule-force-update',
514514
lanes: getLanesFromTransportDecimalBitmask(laneBitmaskString),
515515
componentName,
@@ -527,7 +527,7 @@ function processTimelineEvent(
527527
} else if (name.startsWith('--schedule-state-update-')) {
528528
const [laneBitmaskString, componentName] = name.slice(24).split('-');
529529

530-
const stateUpdateEvent = {
530+
const stateUpdateEvent: SchedulingEvent = {
531531
type: 'schedule-state-update',
532532
lanes: getLanesFromTransportDecimalBitmask(laneBitmaskString),
533533
componentName,
@@ -578,7 +578,7 @@ function processTimelineEvent(
578578
// We can't know if they'll be resolved or not at this point.
579579
// We'll just give them a default (fake) duration width.
580580

581-
const suspenseEvent = {
581+
const suspenseEvent: SuspenseEvent = {
582582
componentName,
583583
depth,
584584
duration: null,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function trackHydrated(
140140
return false;
141141
}
142142

143-
let valueField;
143+
let valueField: 'checked' | 'value';
144144
let expectedValue;
145145
if (isCheckable(node)) {
146146
valueField = 'checked';
@@ -150,8 +150,11 @@ export function trackHydrated(
150150
valueField = 'value';
151151
expectedValue = initialValue;
152152
}
153-
// eslint-disable-next-line react-internal/safe-string-coercion
154-
const currentValue = '' + (node[valueField]: any);
153+
const currentValue =
154+
// eslint-disable-next-line react-internal/safe-string-coercion
155+
'' +
156+
(// $FlowFixMe[prop-missing]
157+
node[valueField]: any);
155158
node._valueTracker = trackValueOnNode(node, valueField, expectedValue);
156159
return currentValue !== expectedValue;
157160
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function createSyntheticEvent(Interface: EventInterfaceType) {
146146
* @interface Event
147147
* @see http://www.w3.org/TR/DOM-Level-3-Events/
148148
*/
149-
const EventInterface = {
149+
const EventInterface: EventInterfaceType = {
150150
eventPhase: 0,
151151
bubbles: 0,
152152
cancelable: 0,
@@ -442,7 +442,7 @@ function getEventModifierState(nativeEvent: {[propName: string]: mixed}) {
442442
* @interface KeyboardEvent
443443
* @see http://www.w3.org/TR/DOM-Level-3-Events/
444444
*/
445-
const KeyboardEventInterface = {
445+
const KeyboardEventInterface: EventInterfaceType = {
446446
...UIEventInterface,
447447
key: getEventKey,
448448
code: 0,
@@ -505,7 +505,7 @@ export const SyntheticKeyboardEvent: $FlowFixMe = createSyntheticEvent(
505505
* @interface PointerEvent
506506
* @see http://www.w3.org/TR/pointerevents/
507507
*/
508-
const PointerEventInterface = {
508+
const PointerEventInterface: EventInterfaceType = {
509509
...MouseEventInterface,
510510
pointerId: 0,
511511
width: 0,
@@ -526,7 +526,7 @@ export const SyntheticPointerEvent: $FlowFixMe = createSyntheticEvent(
526526
* @interface TouchEvent
527527
* @see http://www.w3.org/TR/touch-events/
528528
*/
529-
const TouchEventInterface = {
529+
const TouchEventInterface: EventInterfaceType = {
530530
...UIEventInterface,
531531
touches: 0,
532532
targetTouches: 0,
@@ -545,7 +545,7 @@ export const SyntheticTouchEvent: $FlowFixMe =
545545
* @see http://www.w3.org/TR/2009/WD-css3-transitions-20090320/#transition-events-
546546
* @see https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent
547547
*/
548-
const TransitionEventInterface = {
548+
const TransitionEventInterface: EventInterfaceType = {
549549
...EventInterface,
550550
propertyName: 0,
551551
elapsedTime: 0,
@@ -559,7 +559,7 @@ export const SyntheticTransitionEvent: $FlowFixMe = createSyntheticEvent(
559559
* @interface WheelEvent
560560
* @see http://www.w3.org/TR/DOM-Level-3-Events/
561561
*/
562-
const WheelEventInterface = {
562+
const WheelEventInterface: EventInterfaceType = {
563563
...MouseEventInterface,
564564
deltaX(event: {[propName: string]: mixed}) {
565565
return 'deltaX' in event
@@ -594,7 +594,7 @@ const WheelEventInterface = {
594594
export const SyntheticWheelEvent: $FlowFixMe =
595595
createSyntheticEvent(WheelEventInterface);
596596

597-
const ToggleEventInterface = {
597+
const ToggleEventInterface: EventInterfaceType = {
598598
...EventInterface,
599599
newState: 0,
600600
oldState: 0,

packages/react-dom-bindings/src/shared/ReactDOMFormActions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type FormStatus = FormStatusPending | FormStatusNotPending;
3131

3232
// Since the "not pending" value is always the same, we can reuse the
3333
// same object across all transitions.
34-
const sharedNotPendingObject = {
34+
const sharedNotPendingObject: FormStatusNotPending = {
3535
pending: false,
3636
data: null,
3737
method: null,

packages/react-native-renderer/src/legacy-events/ResponderTouchHistoryStore.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ const ResponderTouchHistoryStore = {
207207
touchHistory.numberActiveTouches = nativeEvent.touches.length;
208208
if (touchHistory.numberActiveTouches === 1) {
209209
touchHistory.indexOfSingleActiveTouch =
210+
// $FlowFixMe[incompatible-type] might be null according to type
210211
nativeEvent.touches[0].identifier;
211212
}
212213
} else if (isEndish(topLevelType)) {

0 commit comments

Comments
 (0)