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) {

0 commit comments

Comments
 (0)