Skip to content

Commit a473d08

Browse files
authored
Update to Flow from 0.97 to 0.122 (#25204)
* flow 0.122 * update ReactModel type
1 parent fe55c0e commit a473d08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+109
-51
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
6464
"fbjs-scripts": "1.2.0",
6565
"filesize": "^6.0.1",
66-
"flow-bin": "0.97",
66+
"flow-bin": "^0.122",
6767
"glob": "^7.1.6",
6868
"glob-stream": "^6.1.0",
6969
"google-closure-compiler": "^20200517.0.0",

packages/jest-react/src/internalAct.js

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
2828
'This version of `act` requires a special mock build of Scheduler.',
2929
);
3030
}
31+
32+
// $FlowFixMe: _isMockFunction doesn't exist on function
3133
if (setTimeout._isMockFunction !== true) {
3234
throw Error(
3335
"This version of `act` requires Jest's timer mocks " +

packages/react-debug-tools/src/ReactDebugHooks.js

+1
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ function handleRenderFunctionError(error: any): void {
683683
// TODO: refactor this if we ever combine the devtools and debug tools packages
684684
wrapperError.name = 'ReactDebugToolsRenderError';
685685
// this stage-4 proposal is not supported by all environments yet.
686+
// $FlowFixMe Flow doesn't have this type yet.
686687
wrapperError.cause = error;
687688
throw wrapperError;
688689
}

packages/react-devtools-shared/src/backend/StyleX/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ function getPropertyValueForStyleName(styleName: string): string | null {
9292
]: any): CSSStyleSheet);
9393
// $FlowFixMe Flow doesn't konw about these properties
9494
const rules = styleSheet.rules || styleSheet.cssRules;
95+
// $FlowFixMe `rules` is mixed
9596
for (let ruleIndex = 0; ruleIndex < rules.length; ruleIndex++) {
97+
// $FlowFixMe `rules` is mixed
9698
const rule = rules[ruleIndex];
9799
// $FlowFixMe Flow doesn't konw about these properties
98100
const {cssText, selectorText, style} = rule;

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ import type {
124124
} from 'react-devtools-shared/src/types';
125125

126126
type getDisplayNameForFiberType = (fiber: Fiber) => string | null;
127-
type getTypeSymbolType = (type: any) => Symbol | number;
127+
type getTypeSymbolType = (type: any) => symbol | number;
128128

129129
type ReactPriorityLevelsType = {|
130130
ImmediatePriority: number,
@@ -382,13 +382,14 @@ export function getInternalReactConstants(
382382
// End of copied code.
383383
// **********************************************************
384384

385-
function getTypeSymbol(type: any): Symbol | number {
385+
function getTypeSymbol(type: any): symbol | number {
386386
const symbolOrNumber =
387387
typeof type === 'object' && type !== null ? type.$$typeof : type;
388388

389389
// $FlowFixMe Flow doesn't know about typeof "symbol"
390390
return typeof symbolOrNumber === 'symbol'
391-
? symbolOrNumber.toString()
391+
? // $FlowFixMe `toString()` doesn't match the type signature?
392+
symbolOrNumber.toString()
392393
: symbolOrNumber;
393394
}
394395

packages/react-devtools-shared/src/backend/types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export type GetFiberIDForNative = (
8484
export type FindNativeNodesForFiberID = (id: number) => ?Array<NativeType>;
8585

8686
export type ReactProviderType<T> = {
87-
$$typeof: Symbol | number,
87+
$$typeof: symbol | number,
8888
_context: ReactContext<T>,
8989
...
9090
};

packages/react-devtools-shared/src/devtools/views/Button.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function Button({
2828
...rest
2929
}: Props) {
3030
let button = (
31+
// $FlowFixMe unsafe spread
3132
<button
3233
className={`${styles.Button} ${className}`}
3334
data-testname={testName}

packages/react-devtools-shared/src/devtools/views/Components/NativeStyleEditor/AutoSizeInput.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default function AutoSizeInput({
4242
const isEmpty = value === '' || value === '""';
4343

4444
return (
45+
// $FlowFixMe unsafe rest spread
4546
<input
4647
className={[styles.Input, className].join(' ')}
4748
data-testname={testName}

packages/react-devtools-shared/src/devtools/views/Components/reach-ui/menu-button.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import useThemeStyles from '../../useThemeStyles';
1919
const MenuList = ({children, ...props}: {children: React$Node, ...}) => {
2020
const style = useThemeStyles();
2121
return (
22+
// $FlowFixMe unsafe spread
2223
<ReachMenuList style={style} {...props}>
2324
{children}
2425
</ReachMenuList>

packages/react-devtools-shared/src/devtools/views/Components/reach-ui/tooltip.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const Tooltip = ({
2323
}) => {
2424
const style = useThemeStyles();
2525
return (
26+
// $FlowFixMe unsafe spread
2627
<ReachTooltip
2728
className={`${tooltipStyles.Tooltip} ${className}`}
2829
style={style}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ export function hydrate(
396396
parent[last] = undefined;
397397
} else {
398398
// Replace the string keys with Symbols so they're non-enumerable.
399-
const replaced: {[key: Symbol]: boolean | string, ...} = {};
399+
const replaced: {[key: symbol]: boolean | string, ...} = {};
400400
replaced[meta.inspectable] = !!value.inspectable;
401401
replaced[meta.inspected] = false;
402402
replaced[meta.name] = value.name;

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

+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/createListComponent.js

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

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function registerDevToolsEventLogger(
3131
let metadata = null;
3232
if (event.metadata != null) {
3333
metadata = event.metadata;
34+
// $FlowFixMe: metadata is not writable and nullable
3435
delete event.metadata;
3536
}
3637
loggingIFrame.contentWindow.postMessage(
@@ -42,7 +43,8 @@ export function registerDevToolsEventLogger(
4243
version: process.env.DEVTOOLS_VERSION,
4344
metadata: metadata !== null ? JSON.stringify(metadata) : '',
4445
...(fetchAdditionalContext != null
45-
? await fetchAdditionalContext()
46+
? // $FlowFixMe
47+
await fetchAdditionalContext()
4648
: {}),
4749
},
4850
},

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ const encodedStringCache: LRUCache<string, Array<number>> = new LRU({
6767
});
6868

6969
export function alphaSortKeys(
70-
a: string | number | Symbol,
71-
b: string | number | Symbol,
70+
a: string | number | symbol,
71+
b: string | number | symbol,
7272
): number {
7373
if (a.toString() > b.toString()) {
7474
return 1;
@@ -81,7 +81,7 @@ export function alphaSortKeys(
8181

8282
export function getAllEnumerableKeys(
8383
obj: Object,
84-
): Set<string | number | Symbol> {
84+
): Set<string | number | symbol> {
8585
const keys = new Set();
8686
let current = obj;
8787
while (current != null) {

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

+24-7
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ let lastMouseEvent;
166166
function updateMouseMovementPolyfillState(event) {
167167
if (event !== lastMouseEvent) {
168168
if (lastMouseEvent && event.type === 'mousemove') {
169+
// $FlowFixMe assuming this is a number
169170
lastMovementX = event.screenX - lastMouseEvent.screenX;
171+
// $FlowFixMe assuming this is a number
170172
lastMovementY = event.screenY - lastMouseEvent.screenY;
171173
} else {
172174
lastMovementX = 0;
@@ -367,15 +369,20 @@ function getEventKey(nativeEvent) {
367369

368370
// FireFox implements `key` but returns `MozPrintableKey` for all
369371
// printable characters (normalized to `Unidentified`), ignore it.
370-
const key = normalizeKey[nativeEvent.key] || nativeEvent.key;
372+
const key =
373+
// $FlowFixMe unable to index with a `mixed` value
374+
normalizeKey[nativeEvent.key] || nativeEvent.key;
371375
if (key !== 'Unidentified') {
372376
return key;
373377
}
374378
}
375379

376380
// Browser does not implement `key`, polyfill as much of it as we can.
377381
if (nativeEvent.type === 'keypress') {
378-
const charCode = getEventCharCode(nativeEvent);
382+
const charCode = getEventCharCode(
383+
// $FlowFixMe unable to narrow to `KeyboardEvent`
384+
nativeEvent,
385+
);
379386

380387
// The enter-key is technically both printable and non-printable and can
381388
// thus be captured by `keypress`, no other non-printable key should.
@@ -384,6 +391,7 @@ function getEventKey(nativeEvent) {
384391
if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
385392
// While user keyboard layout determines the actual meaning of each
386393
// `keyCode` value, almost all function keys have a universal value.
394+
// $FlowFixMe unable to index with a `mixed` value
387395
return translateToKey[nativeEvent.keyCode] || 'Unidentified';
388396
}
389397
return '';
@@ -441,7 +449,10 @@ const KeyboardEventInterface = {
441449
// KeyPress is deprecated, but its replacement is not yet final and not
442450
// implemented in any major browser. Only KeyPress has charCode.
443451
if (event.type === 'keypress') {
444-
return getEventCharCode(event);
452+
return getEventCharCode(
453+
// $FlowFixMe unable to narrow to `KeyboardEvent`
454+
event,
455+
);
445456
}
446457
return 0;
447458
},
@@ -462,7 +473,10 @@ const KeyboardEventInterface = {
462473
// `which` is an alias for either `keyCode` or `charCode` depending on the
463474
// type of the event.
464475
if (event.type === 'keypress') {
465-
return getEventCharCode(event);
476+
return getEventCharCode(
477+
// $FlowFixMe unable to narrow to `KeyboardEvent`
478+
event,
479+
);
466480
}
467481
if (event.type === 'keydown' || event.type === 'keyup') {
468482
return event.keyCode;
@@ -538,18 +552,21 @@ const WheelEventInterface = {
538552
? event.deltaX
539553
: // Fallback to `wheelDeltaX` for Webkit and normalize (right is positive).
540554
'wheelDeltaX' in event
541-
? -event.wheelDeltaX
555+
? // $FlowFixMe assuming this is a number
556+
-event.wheelDeltaX
542557
: 0;
543558
},
544559
deltaY(event) {
545560
return 'deltaY' in event
546561
? event.deltaY
547562
: // Fallback to `wheelDeltaY` for Webkit and normalize (down is positive).
548563
'wheelDeltaY' in event
549-
? -event.wheelDeltaY
564+
? // $FlowFixMe assuming this is a number
565+
-event.wheelDeltaY
550566
: // Fallback to `wheelDelta` for IE<9 and normalize (down is positive).
551567
'wheelDelta' in event
552-
? -event.wheelDelta
568+
? // $FlowFixMe assuming this is a number
569+
-event.wheelDelta
553570
: 0;
554571
},
555572
deltaZ: 0,

packages/react-dom/src/server/ReactDOMFizzServerBrowser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ function renderToReadableStream(
5757
const stream: ReactDOMServerReadableStream = (new ReadableStream(
5858
{
5959
type: 'bytes',
60-
pull(controller) {
60+
pull(controller): ?Promise<void> {
6161
startFlowing(request, controller);
6262
},
63-
cancel(reason) {
63+
cancel(reason): ?Promise<void> {
6464
abort(request);
6565
},
6666
},

packages/react-dom/src/server/ReactDOMFizzStaticBrowser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function prerender(
5050
const stream = new ReadableStream(
5151
{
5252
type: 'bytes',
53-
pull(controller) {
53+
pull(controller): ?Promise<void> {
5454
startFlowing(request, controller);
5555
},
5656
},

packages/react-fetch/src/ReactFetchNode.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function nodeFetch(
4343
// TODO: cherry-pick supported user-passed options.
4444
};
4545
const nodeImpl = protocol === 'https:' ? https : http;
46+
// $FlowFixMe: node flow type has `port` as a number
4647
const request = nodeImpl.request(nodeOptions, response => {
4748
// TODO: support redirects.
4849
onResolve(new Response(response));

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

+2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ function accumulateInto<T>(
4040
// certain that x is an Array (x could be a string with concat method).
4141
if (isArray(current)) {
4242
if (isArray(next)) {
43+
// $FlowFixMe `isArray` does not ensure array is mutable
4344
current.push.apply(current, next);
4445
return current;
4546
}
47+
// $FlowFixMe `isArray` does not ensure array is mutable
4648
current.push(next);
4749
return current;
4850
}

packages/react-noop-renderer/src/ReactNoopFlightServer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const ReactNoopFlightServer = ReactFlightServer({
5353
},
5454
resolveModuleMetaData(
5555
config: void,
56-
reference: {$$typeof: Symbol, value: any},
56+
reference: {$$typeof: symbol, value: any},
5757
) {
5858
return saveModule(reference.value);
5959
},

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

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ if (__DEV__) {
8080
);
8181
}
8282

83+
// $FlowFixMe unable to narrow type from mixed to writable object
8384
child._store.validated = true;
8485

8586
const componentName = getComponentNameFromFiber(returnFiber) || 'Component';

packages/react-reconciler/src/ReactChildFiber.old.js

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ if (__DEV__) {
8080
);
8181
}
8282

83+
// $FlowFixMe unable to narrow type from mixed to writable object
8384
child._store.validated = true;
8485

8586
const componentName = getComponentNameFromFiber(returnFiber) || 'Component';

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

+3
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
296296
}
297297
}
298298
} else {
299+
// $FlowFixMe unable to narrow type to RefObject
299300
ref.current = null;
300301
}
301302
}
@@ -1522,6 +1523,7 @@ function commitAttachRef(finishedWork: Fiber) {
15221523
}
15231524
}
15241525

1526+
// $FlowFixMe unable to narrow type to the non-function case
15251527
ref.current = instanceToUse;
15261528
}
15271529
}
@@ -1542,6 +1544,7 @@ function commitDetachRef(current: Fiber) {
15421544
currentRef(null);
15431545
}
15441546
} else {
1547+
// $FlowFixMe unable to narrow type to the non-function case
15451548
currentRef.current = null;
15461549
}
15471550
}

packages/react-reconciler/src/ReactFiberCommitWork.old.js

+3
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
296296
}
297297
}
298298
} else {
299+
// $FlowFixMe unable to narrow type to RefObject
299300
ref.current = null;
300301
}
301302
}
@@ -1522,6 +1523,7 @@ function commitAttachRef(finishedWork: Fiber) {
15221523
}
15231524
}
15241525

1526+
// $FlowFixMe unable to narrow type to the non-function case
15251527
ref.current = instanceToUse;
15261528
}
15271529
}
@@ -1542,6 +1544,7 @@ function commitDetachRef(current: Fiber) {
15421544
currentRef(null);
15431545
}
15441546
} else {
1547+
// $FlowFixMe unable to narrow type to the non-function case
15451548
currentRef.current = null;
15461549
}
15471550
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export function markFailedErrorBoundaryForHotReloading(fiber: Fiber) {
222222
return;
223223
}
224224
if (failedBoundaries === null) {
225+
// $FlowFixMe Flow got confused by the feature check above.
225226
failedBoundaries = new WeakSet();
226227
}
227228
failedBoundaries.add(fiber);

packages/react-reconciler/src/ReactFiberHotReloading.old.js

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export function markFailedErrorBoundaryForHotReloading(fiber: Fiber) {
222222
return;
223223
}
224224
if (failedBoundaries === null) {
225+
// $FlowFixMe Flow got confused by the feature check above.
225226
failedBoundaries = new WeakSet();
226227
}
227228
failedBoundaries.add(fiber);

packages/react-reconciler/src/ReactTestSelectors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if (typeof Symbol === 'function' && Symbol.for) {
3939
TEXT_TYPE = symbolFor('selector.text');
4040
}
4141

42-
type Type = Symbol | number;
42+
type Type = symbol | number;
4343

4444
type ComponentSelector = {|
4545
$$typeof: Type,

0 commit comments

Comments
 (0)