@samitouri / QOS-React-2 / commits / 5fdcd23aaa

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.

Jan Kassens committed Sep 13, 2022 at 13:33 UTC 5fdcd23aaa30a13eead12b7661a3a5903c6837f1
16 files changed +68 -25
package.json
+1 -1
@@ -63,7 +63,7 @@
63 "eslint-plugin-react-internal": "link:./scripts/eslint-rules",
64 "fbjs-scripts": "1.2.0",
65 "filesize": "^6.0.1",
66 - "flow-bin": "^0.132",
66 + "flow-bin": "^0.140",
67 "glob": "^7.1.6",
68 "glob-stream": "^6.1.0",
69 "google-closure-compiler": "^20200517.0.0",
packages/react-cache/src/LRU.js
+9 -2
@@ -23,7 +23,14 @@ type Entry<T> = {
23 next: Entry<T>,
24 };
25
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> {
34 let LIMIT = limit;
35
36 // Circular, doubly-linked list
@@ -135,7 +142,7 @@ export function createLRU<T>(limit: number) {
142 return entry.value;
143 }
144
138 - function setLimit(newLimit: number) {
145 + function setLimit(newLimit: number): void {
146 LIMIT = newLimit;
147 scheduleCleanUp();
148 }
packages/react-cache/src/ReactCacheOld.js
+1
@@ -122,6 +122,7 @@ function accessResult<I, K, V>(
122 status: Pending,
123 value: thenable,
124 };
125 + // $FlowFixMe[escaped-generic] discovered when updating Flow
126 const newEntry = lru.add(newResult, deleteEntry.bind(null, resource, key));
127 entriesForResource.set(key, newEntry);
128 return newResult;
packages/react-dom/src/client/ReactDOMInput.js
+1
@@ -177,6 +177,7 @@ export function updateWrapper(element: Element, props: Object) {
177 if (value != null) {
178 if (type === 'number') {
179 if (
180 + // $FlowFixMe[incompatible-type]
181 (value === 0 && node.value === '') ||
182 // We explicitly want to coerce to number here if possible.
183 // eslint-disable-next-line
packages/react-dom/src/server/ReactDOMFizzServerNode.js
+2 -1
@@ -10,6 +10,7 @@
10 import type {ReactNodeList} from 'shared/ReactTypes';
11 import type {Writable} from 'stream';
12 import type {BootstrapScriptDescriptor} from './ReactDOMServerFormatConfig';
13 +import type {Destination} from 'react-server/src/ReactServerStreamConfigNode';
14
15 import ReactVersion from 'shared/ReactVersion';
16
@@ -25,7 +26,7 @@ import {
26 createRootFormatContext,
27 } from './ReactDOMServerFormatConfig';
28
28 -function createDrainHandler(destination, request) {
29 +function createDrainHandler(destination: Destination, request) {
30 return () => startFlowing(request, destination);
31 }
32
packages/react-native-renderer/src/legacy-events/accumulate.js
+2
@@ -33,6 +33,8 @@ function accumulate<T>(
33 // Both are not empty. Warning: Never call x.concat(y) when you are not
34 // certain that x is an Array (x could be a string with concat method).
35 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` */
38 return current.concat(next);
39 }
40
packages/react-native-renderer/src/legacy-events/forEachAccumulated.js
+1
@@ -22,6 +22,7 @@ function forEachAccumulated<T>(
22 scope: ?any,
23 ) {
24 if (Array.isArray(arr)) {
25 + // $FlowFixMe[incompatible-call] if `T` is an array, `cb` cannot be called
26 arr.forEach(cb, scope);
27 } else if (arr) {
28 cb.call(scope, arr);
packages/react-reconciler/src/ReactFiberClassUpdateQueue.new.js
+1
@@ -476,6 +476,7 @@ export function processUpdateQueue<State>(
476 hasForceUpdate = false;
477
478 if (__DEV__) {
479 + // $FlowFixMe[escaped-generic] discovered when updating Flow
480 currentlyProcessingQueue = queue.shared;
481 }
482
packages/react-reconciler/src/ReactFiberClassUpdateQueue.old.js
+1
@@ -476,6 +476,7 @@ export function processUpdateQueue<State>(
476 hasForceUpdate = false;
477
478 if (__DEV__) {
479 + // $FlowFixMe[escaped-generic] discovered when updating Flow
480 currentlyProcessingQueue = queue.shared;
481 }
482
packages/react-reconciler/src/ReactFiberHooks.new.js
+18 -7
@@ -160,7 +160,7 @@ export type Effect = {
160 tag: HookFlags,
161 create: () => (() => void) | void,
162 destroy: (() => void) | void,
163 - deps: Array<mixed> | null,
163 + deps: Array<mixed> | void | null,
164 next: Effect,
165 };
166
@@ -1539,7 +1539,7 @@ function updateStoreInstance<T>(
1539 }
1540 }
1541
1542 -function subscribeToStore(fiber, inst, subscribe) {
1542 +function subscribeToStore<T>(fiber, inst: StoreInstance<T>, subscribe) {
1543 const handleStoreChange = () => {
1544 // The store changed. Check if the snapshot changed since the last time we
1545 // read from the store.
@@ -1552,7 +1552,7 @@ function subscribeToStore(fiber, inst, subscribe) {
1552 return subscribe(handleStoreChange);
1553 }
1554
1555 -function checkIfSnapshotChanged(inst) {
1555 +function checkIfSnapshotChanged<T>(inst: StoreInstance<T>): boolean {
1556 const latestGetSnapshot = inst.getSnapshot;
1557 const prevValue = inst.value;
1558 try {
@@ -1609,7 +1609,7 @@ function rerenderState<S>(
1609 return rerenderReducer(basicStateReducer, (initialState: any));
1610 }
1611
1612 -function pushEffect(tag, create, destroy, deps) {
1612 +function pushEffect(tag, create, destroy, deps: Array<mixed> | void | null) {
1613 const effect: Effect = {
1614 tag,
1615 create,
@@ -1728,7 +1728,12 @@ function updateRef<T>(initialValue: T): {current: T} {
1728 return hook.memoizedState;
1729 }
1730
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 {
1737 const hook = mountWorkInProgressHook();
1738 const nextDeps = deps === undefined ? null : deps;
1739 currentlyRenderingFiber.flags |= fiberFlags;
@@ -1740,7 +1745,12 @@ function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
1745 );
1746 }
1747
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 {
1754 const hook = updateWorkInProgressHook();
1755 const nextDeps = deps === undefined ? null : deps;
1756 let destroy = undefined;
@@ -2395,7 +2405,7 @@ function entangleTransitionUpdate<S, A>(
2405 }
2406 }
2407
2398 -function markUpdateInDevTools(fiber, lane, action) {
2408 +function markUpdateInDevTools<A>(fiber, lane, action: A) {
2409 if (__DEV__) {
2410 if (enableDebugTracing) {
2411 if (fiber.mode & DebugTracingMode) {
@@ -2490,6 +2500,7 @@ const HooksDispatcherOnMount: Dispatcher = {
2500 if (enableCache) {
2501 (HooksDispatcherOnMount: Dispatcher).getCacheSignal = getCacheSignal;
2502 (HooksDispatcherOnMount: Dispatcher).getCacheForType = getCacheForType;
2503 + // $FlowFixMe[escaped-generic] discovered when updating Flow
2504 (HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
2505 }
2506 if (enableUseHook) {
packages/react-reconciler/src/ReactFiberHooks.old.js
+18 -7
@@ -160,7 +160,7 @@ export type Effect = {
160 tag: HookFlags,
161 create: () => (() => void) | void,
162 destroy: (() => void) | void,
163 - deps: Array<mixed> | null,
163 + deps: Array<mixed> | void | null,
164 next: Effect,
165 };
166
@@ -1539,7 +1539,7 @@ function updateStoreInstance<T>(
1539 }
1540 }
1541
1542 -function subscribeToStore(fiber, inst, subscribe) {
1542 +function subscribeToStore<T>(fiber, inst: StoreInstance<T>, subscribe) {
1543 const handleStoreChange = () => {
1544 // The store changed. Check if the snapshot changed since the last time we
1545 // read from the store.
@@ -1552,7 +1552,7 @@ function subscribeToStore(fiber, inst, subscribe) {
1552 return subscribe(handleStoreChange);
1553 }
1554
1555 -function checkIfSnapshotChanged(inst) {
1555 +function checkIfSnapshotChanged<T>(inst: StoreInstance<T>): boolean {
1556 const latestGetSnapshot = inst.getSnapshot;
1557 const prevValue = inst.value;
1558 try {
@@ -1609,7 +1609,7 @@ function rerenderState<S>(
1609 return rerenderReducer(basicStateReducer, (initialState: any));
1610 }
1611
1612 -function pushEffect(tag, create, destroy, deps) {
1612 +function pushEffect(tag, create, destroy, deps: Array<mixed> | void | null) {
1613 const effect: Effect = {
1614 tag,
1615 create,
@@ -1728,7 +1728,12 @@ function updateRef<T>(initialValue: T): {current: T} {
1728 return hook.memoizedState;
1729 }
1730
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 {
1737 const hook = mountWorkInProgressHook();
1738 const nextDeps = deps === undefined ? null : deps;
1739 currentlyRenderingFiber.flags |= fiberFlags;
@@ -1740,7 +1745,12 @@ function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
1745 );
1746 }
1747
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 {
1754 const hook = updateWorkInProgressHook();
1755 const nextDeps = deps === undefined ? null : deps;
1756 let destroy = undefined;
@@ -2395,7 +2405,7 @@ function entangleTransitionUpdate<S, A>(
2405 }
2406 }
2407
2398 -function markUpdateInDevTools(fiber, lane, action) {
2408 +function markUpdateInDevTools<A>(fiber, lane, action: A) {
2409 if (__DEV__) {
2410 if (enableDebugTracing) {
2411 if (fiber.mode & DebugTracingMode) {
@@ -2490,6 +2500,7 @@ const HooksDispatcherOnMount: Dispatcher = {
2500 if (enableCache) {
2501 (HooksDispatcherOnMount: Dispatcher).getCacheSignal = getCacheSignal;
2502 (HooksDispatcherOnMount: Dispatcher).getCacheForType = getCacheForType;
2503 + // $FlowFixMe[escaped-generic] discovered when updating Flow
2504 (HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
2505 }
2506 if (enableUseHook) {
packages/react-refresh/src/ReactFreshRuntime.js
+1
@@ -654,6 +654,7 @@ export function createSignatureFunctionForTransform() {
654 // in HOC chains like _s(hoc1(_s(hoc2(_s(actualFunction))))).
655 if (!savedType) {
656 // We're in the innermost call, so this is the actual type.
657 + // $FlowFixMe[escaped-generic] discovered when updating Flow
658 savedType = type;
659 hasCustomHooks = typeof getCustomHooks === 'function';
660 }
packages/react-server-dom-webpack/src/ReactFlightDOMServerNode.js
+2 -1
@@ -8,6 +8,7 @@
8 */
9
10 import type {ReactModel} from 'react-server/src/ReactFlightServer';
11 +import type {Destination} from 'react-server/src/ReactServerStreamConfigNode';
12 import type {BundlerConfig} from './ReactFlightServerWebpackBundlerConfig';
13 import type {Writable} from 'stream';
14 import type {ServerContextJSONValue} from 'shared/ReactTypes';
@@ -19,7 +20,7 @@ import {
20 abort,
21 } from 'react-server/src/ReactFlightServer';
22
22 -function createDrainHandler(destination, request) {
23 +function createDrainHandler(destination: Destination, request) {
24 return () => startFlowing(request, destination);
25 }
26
packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js
+4 -1
@@ -128,7 +128,10 @@ export function useSyncExternalStore<T>(
128 return value;
129 }
130
131 -function checkIfSnapshotChanged(inst) {
131 +function checkIfSnapshotChanged<T>(inst: {
132 + value: T,
133 + getSnapshot: () => T,
134 +}): boolean {
135 const latestGetSnapshot = inst.getSnapshot;
136 const prevValue = inst.value;
137 try {
scripts/flow/config/flowconfig
+2 -1
@@ -45,9 +45,10 @@ esproposal.class_instance_fields=enable
45 esproposal.optional_chaining=enable
46 exact_by_default=true
47 munge_underscores=false
48 +types_first=false
49
50 # Substituted by createFlowConfig.js:
51 %REACT_RENDERER_FLOW_OPTIONS%
52
53 [version]
53 -^0.132.0
54 +^0.140.0
yarn.lock
+4 -4
@@ -7914,10 +7914,10 @@ flatted@^2.0.0:
7914 resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
7915 integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==
7916
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==
7921
7922 fluent-syntax@0.13.0:
7923 version "0.13.0"