Skip to content

Commit 5fdcd23

Browse files
authored
Flow: upgrade to 0.140 (#25252)
This update range includes: - `types_first` ([blog](https://flow.org/en/docs/lang/types-first/), all exports need annotated types) is default. I disabled this for now to make that change incremental. - Generics that escape the scope they are defined in are an error. I fixed some with explicit type annotations and some are suppressed that I didn't easily figure out.
1 parent e6a062b commit 5fdcd23

File tree

16 files changed

+68
-25
lines changed

16 files changed

+68
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
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.132",
66+
"flow-bin": "^0.140",
6767
"glob": "^7.1.6",
6868
"glob-stream": "^6.1.0",
6969
"google-closure-compiler": "^20200517.0.0",

packages/react-cache/src/LRU.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ type Entry<T> = {
2323
next: Entry<T>,
2424
};
2525

26-
export function createLRU<T>(limit: number) {
26+
type LRU<T> = {
27+
add(value: Object, onDelete: () => mixed): Entry<Object>,
28+
update(entry: Entry<T>, newValue: T): void,
29+
access(entry: Entry<T>): T,
30+
setLimit(newLimit: number): void,
31+
};
32+
33+
export function createLRU<T>(limit: number): LRU<T> {
2734
let LIMIT = limit;
2835

2936
// Circular, doubly-linked list
@@ -135,7 +142,7 @@ export function createLRU<T>(limit: number) {
135142
return entry.value;
136143
}
137144

138-
function setLimit(newLimit: number) {
145+
function setLimit(newLimit: number): void {
139146
LIMIT = newLimit;
140147
scheduleCleanUp();
141148
}

packages/react-cache/src/ReactCacheOld.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ function accessResult<I, K, V>(
122122
status: Pending,
123123
value: thenable,
124124
};
125+
// $FlowFixMe[escaped-generic] discovered when updating Flow
125126
const newEntry = lru.add(newResult, deleteEntry.bind(null, resource, key));
126127
entriesForResource.set(key, newEntry);
127128
return newResult;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export function updateWrapper(element: Element, props: Object) {
177177
if (value != null) {
178178
if (type === 'number') {
179179
if (
180+
// $FlowFixMe[incompatible-type]
180181
(value === 0 && node.value === '') ||
181182
// We explicitly want to coerce to number here if possible.
182183
// eslint-disable-next-line

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import type {ReactNodeList} from 'shared/ReactTypes';
1111
import type {Writable} from 'stream';
1212
import type {BootstrapScriptDescriptor} from './ReactDOMServerFormatConfig';
13+
import type {Destination} from 'react-server/src/ReactServerStreamConfigNode';
1314

1415
import ReactVersion from 'shared/ReactVersion';
1516

@@ -25,7 +26,7 @@ import {
2526
createRootFormatContext,
2627
} from './ReactDOMServerFormatConfig';
2728

28-
function createDrainHandler(destination, request) {
29+
function createDrainHandler(destination: Destination, request) {
2930
return () => startFlowing(request, destination);
3031
}
3132

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ function accumulate<T>(
3333
// Both are not empty. Warning: Never call x.concat(y) when you are not
3434
// certain that x is an Array (x could be a string with concat method).
3535
if (isArray(current)) {
36+
/* $FlowFixMe[incompatible-return] if `current` is `T` and `T` an array,
37+
* `isArray` might refine to the array element type of `T` */
3638
return current.concat(next);
3739
}
3840

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function forEachAccumulated<T>(
2222
scope: ?any,
2323
) {
2424
if (Array.isArray(arr)) {
25+
// $FlowFixMe[incompatible-call] if `T` is an array, `cb` cannot be called
2526
arr.forEach(cb, scope);
2627
} else if (arr) {
2728
cb.call(scope, arr);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ export function processUpdateQueue<State>(
476476
hasForceUpdate = false;
477477

478478
if (__DEV__) {
479+
// $FlowFixMe[escaped-generic] discovered when updating Flow
479480
currentlyProcessingQueue = queue.shared;
480481
}
481482

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ export function processUpdateQueue<State>(
476476
hasForceUpdate = false;
477477

478478
if (__DEV__) {
479+
// $FlowFixMe[escaped-generic] discovered when updating Flow
479480
currentlyProcessingQueue = queue.shared;
480481
}
481482

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export type Effect = {
160160
tag: HookFlags,
161161
create: () => (() => void) | void,
162162
destroy: (() => void) | void,
163-
deps: Array<mixed> | null,
163+
deps: Array<mixed> | void | null,
164164
next: Effect,
165165
};
166166

@@ -1539,7 +1539,7 @@ function updateStoreInstance<T>(
15391539
}
15401540
}
15411541

1542-
function subscribeToStore(fiber, inst, subscribe) {
1542+
function subscribeToStore<T>(fiber, inst: StoreInstance<T>, subscribe) {
15431543
const handleStoreChange = () => {
15441544
// The store changed. Check if the snapshot changed since the last time we
15451545
// read from the store.
@@ -1552,7 +1552,7 @@ function subscribeToStore(fiber, inst, subscribe) {
15521552
return subscribe(handleStoreChange);
15531553
}
15541554

1555-
function checkIfSnapshotChanged(inst) {
1555+
function checkIfSnapshotChanged<T>(inst: StoreInstance<T>): boolean {
15561556
const latestGetSnapshot = inst.getSnapshot;
15571557
const prevValue = inst.value;
15581558
try {
@@ -1609,7 +1609,7 @@ function rerenderState<S>(
16091609
return rerenderReducer(basicStateReducer, (initialState: any));
16101610
}
16111611

1612-
function pushEffect(tag, create, destroy, deps) {
1612+
function pushEffect(tag, create, destroy, deps: Array<mixed> | void | null) {
16131613
const effect: Effect = {
16141614
tag,
16151615
create,
@@ -1728,7 +1728,12 @@ function updateRef<T>(initialValue: T): {current: T} {
17281728
return hook.memoizedState;
17291729
}
17301730

1731-
function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
1731+
function mountEffectImpl(
1732+
fiberFlags,
1733+
hookFlags,
1734+
create,
1735+
deps: Array<mixed> | void | null,
1736+
): void {
17321737
const hook = mountWorkInProgressHook();
17331738
const nextDeps = deps === undefined ? null : deps;
17341739
currentlyRenderingFiber.flags |= fiberFlags;
@@ -1740,7 +1745,12 @@ function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
17401745
);
17411746
}
17421747

1743-
function updateEffectImpl(fiberFlags, hookFlags, create, deps): void {
1748+
function updateEffectImpl(
1749+
fiberFlags,
1750+
hookFlags,
1751+
create,
1752+
deps: Array<mixed> | void | null,
1753+
): void {
17441754
const hook = updateWorkInProgressHook();
17451755
const nextDeps = deps === undefined ? null : deps;
17461756
let destroy = undefined;
@@ -2395,7 +2405,7 @@ function entangleTransitionUpdate<S, A>(
23952405
}
23962406
}
23972407

2398-
function markUpdateInDevTools(fiber, lane, action) {
2408+
function markUpdateInDevTools<A>(fiber, lane, action: A) {
23992409
if (__DEV__) {
24002410
if (enableDebugTracing) {
24012411
if (fiber.mode & DebugTracingMode) {
@@ -2490,6 +2500,7 @@ const HooksDispatcherOnMount: Dispatcher = {
24902500
if (enableCache) {
24912501
(HooksDispatcherOnMount: Dispatcher).getCacheSignal = getCacheSignal;
24922502
(HooksDispatcherOnMount: Dispatcher).getCacheForType = getCacheForType;
2503+
// $FlowFixMe[escaped-generic] discovered when updating Flow
24932504
(HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
24942505
}
24952506
if (enableUseHook) {

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export type Effect = {
160160
tag: HookFlags,
161161
create: () => (() => void) | void,
162162
destroy: (() => void) | void,
163-
deps: Array<mixed> | null,
163+
deps: Array<mixed> | void | null,
164164
next: Effect,
165165
};
166166

@@ -1539,7 +1539,7 @@ function updateStoreInstance<T>(
15391539
}
15401540
}
15411541

1542-
function subscribeToStore(fiber, inst, subscribe) {
1542+
function subscribeToStore<T>(fiber, inst: StoreInstance<T>, subscribe) {
15431543
const handleStoreChange = () => {
15441544
// The store changed. Check if the snapshot changed since the last time we
15451545
// read from the store.
@@ -1552,7 +1552,7 @@ function subscribeToStore(fiber, inst, subscribe) {
15521552
return subscribe(handleStoreChange);
15531553
}
15541554

1555-
function checkIfSnapshotChanged(inst) {
1555+
function checkIfSnapshotChanged<T>(inst: StoreInstance<T>): boolean {
15561556
const latestGetSnapshot = inst.getSnapshot;
15571557
const prevValue = inst.value;
15581558
try {
@@ -1609,7 +1609,7 @@ function rerenderState<S>(
16091609
return rerenderReducer(basicStateReducer, (initialState: any));
16101610
}
16111611

1612-
function pushEffect(tag, create, destroy, deps) {
1612+
function pushEffect(tag, create, destroy, deps: Array<mixed> | void | null) {
16131613
const effect: Effect = {
16141614
tag,
16151615
create,
@@ -1728,7 +1728,12 @@ function updateRef<T>(initialValue: T): {current: T} {
17281728
return hook.memoizedState;
17291729
}
17301730

1731-
function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
1731+
function mountEffectImpl(
1732+
fiberFlags,
1733+
hookFlags,
1734+
create,
1735+
deps: Array<mixed> | void | null,
1736+
): void {
17321737
const hook = mountWorkInProgressHook();
17331738
const nextDeps = deps === undefined ? null : deps;
17341739
currentlyRenderingFiber.flags |= fiberFlags;
@@ -1740,7 +1745,12 @@ function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
17401745
);
17411746
}
17421747

1743-
function updateEffectImpl(fiberFlags, hookFlags, create, deps): void {
1748+
function updateEffectImpl(
1749+
fiberFlags,
1750+
hookFlags,
1751+
create,
1752+
deps: Array<mixed> | void | null,
1753+
): void {
17441754
const hook = updateWorkInProgressHook();
17451755
const nextDeps = deps === undefined ? null : deps;
17461756
let destroy = undefined;
@@ -2395,7 +2405,7 @@ function entangleTransitionUpdate<S, A>(
23952405
}
23962406
}
23972407

2398-
function markUpdateInDevTools(fiber, lane, action) {
2408+
function markUpdateInDevTools<A>(fiber, lane, action: A) {
23992409
if (__DEV__) {
24002410
if (enableDebugTracing) {
24012411
if (fiber.mode & DebugTracingMode) {
@@ -2490,6 +2500,7 @@ const HooksDispatcherOnMount: Dispatcher = {
24902500
if (enableCache) {
24912501
(HooksDispatcherOnMount: Dispatcher).getCacheSignal = getCacheSignal;
24922502
(HooksDispatcherOnMount: Dispatcher).getCacheForType = getCacheForType;
2503+
// $FlowFixMe[escaped-generic] discovered when updating Flow
24932504
(HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
24942505
}
24952506
if (enableUseHook) {

packages/react-refresh/src/ReactFreshRuntime.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ export function createSignatureFunctionForTransform() {
654654
// in HOC chains like _s(hoc1(_s(hoc2(_s(actualFunction))))).
655655
if (!savedType) {
656656
// We're in the innermost call, so this is the actual type.
657+
// $FlowFixMe[escaped-generic] discovered when updating Flow
657658
savedType = type;
658659
hasCustomHooks = typeof getCustomHooks === 'function';
659660
}

packages/react-server-dom-webpack/src/ReactFlightDOMServerNode.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import type {ReactModel} from 'react-server/src/ReactFlightServer';
11+
import type {Destination} from 'react-server/src/ReactServerStreamConfigNode';
1112
import type {BundlerConfig} from './ReactFlightServerWebpackBundlerConfig';
1213
import type {Writable} from 'stream';
1314
import type {ServerContextJSONValue} from 'shared/ReactTypes';
@@ -19,7 +20,7 @@ import {
1920
abort,
2021
} from 'react-server/src/ReactFlightServer';
2122

22-
function createDrainHandler(destination, request) {
23+
function createDrainHandler(destination: Destination, request) {
2324
return () => startFlowing(request, destination);
2425
}
2526

packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ export function useSyncExternalStore<T>(
128128
return value;
129129
}
130130

131-
function checkIfSnapshotChanged(inst) {
131+
function checkIfSnapshotChanged<T>(inst: {
132+
value: T,
133+
getSnapshot: () => T,
134+
}): boolean {
132135
const latestGetSnapshot = inst.getSnapshot;
133136
const prevValue = inst.value;
134137
try {

scripts/flow/config/flowconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ esproposal.class_instance_fields=enable
4545
esproposal.optional_chaining=enable
4646
exact_by_default=true
4747
munge_underscores=false
48+
types_first=false
4849

4950
# Substituted by createFlowConfig.js:
5051
%REACT_RENDERER_FLOW_OPTIONS%
5152

5253
[version]
53-
^0.132.0
54+
^0.140.0

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7914,10 +7914,10 @@ flatted@^2.0.0:
79147914
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
79157915
integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==
79167916

7917-
flow-bin@^0.132:
7918-
version "0.132.0"
7919-
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.132.0.tgz#8bf80a79630db24bd1422dc2cc4b5e97f97ccb98"
7920-
integrity sha512-S1g/vnAyNaLUdajmuUHCMl30qqye12gS6mr4LVyswf1k+JDF4efs6SfKmptuvnpitF3LGCVf0TIffChP8ljwnw==
7917+
flow-bin@^0.140:
7918+
version "0.140.0"
7919+
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.140.0.tgz#bf1a2984a0e5604daa0d1e0432138d9897af65bb"
7920+
integrity sha512-9P/VciKACXocClhLiDg/p1ntYmgCEEc9QrNOoTqTi2SEdEZDTiAmJLONRJfw4uglPVRZ1p/esWF9KlbZiuxqVw==
79217921

79227922
79237923
version "0.13.0"

0 commit comments

Comments
 (0)