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.
This commit is contained in:
Jan Kassens 2022-09-13 13:33:43 -04:00 committed by GitHub
parent e6a062bd2a
commit 5fdcd23aaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 68 additions and 25 deletions

View File

@ -63,7 +63,7 @@
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
"fbjs-scripts": "1.2.0",
"filesize": "^6.0.1",
"flow-bin": "^0.132",
"flow-bin": "^0.140",
"glob": "^7.1.6",
"glob-stream": "^6.1.0",
"google-closure-compiler": "^20200517.0.0",

View File

@ -23,7 +23,14 @@ type Entry<T> = {
next: Entry<T>,
};
export function createLRU<T>(limit: number) {
type LRU<T> = {
add(value: Object, onDelete: () => mixed): Entry<Object>,
update(entry: Entry<T>, newValue: T): void,
access(entry: Entry<T>): T,
setLimit(newLimit: number): void,
};
export function createLRU<T>(limit: number): LRU<T> {
let LIMIT = limit;
// Circular, doubly-linked list
@ -135,7 +142,7 @@ export function createLRU<T>(limit: number) {
return entry.value;
}
function setLimit(newLimit: number) {
function setLimit(newLimit: number): void {
LIMIT = newLimit;
scheduleCleanUp();
}

View File

@ -122,6 +122,7 @@ function accessResult<I, K, V>(
status: Pending,
value: thenable,
};
// $FlowFixMe[escaped-generic] discovered when updating Flow
const newEntry = lru.add(newResult, deleteEntry.bind(null, resource, key));
entriesForResource.set(key, newEntry);
return newResult;

View File

@ -177,6 +177,7 @@ export function updateWrapper(element: Element, props: Object) {
if (value != null) {
if (type === 'number') {
if (
// $FlowFixMe[incompatible-type]
(value === 0 && node.value === '') ||
// We explicitly want to coerce to number here if possible.
// eslint-disable-next-line

View File

@ -10,6 +10,7 @@
import type {ReactNodeList} from 'shared/ReactTypes';
import type {Writable} from 'stream';
import type {BootstrapScriptDescriptor} from './ReactDOMServerFormatConfig';
import type {Destination} from 'react-server/src/ReactServerStreamConfigNode';
import ReactVersion from 'shared/ReactVersion';
@ -25,7 +26,7 @@ import {
createRootFormatContext,
} from './ReactDOMServerFormatConfig';
function createDrainHandler(destination, request) {
function createDrainHandler(destination: Destination, request) {
return () => startFlowing(request, destination);
}

View File

@ -33,6 +33,8 @@ function accumulate<T>(
// Both are not empty. Warning: Never call x.concat(y) when you are not
// certain that x is an Array (x could be a string with concat method).
if (isArray(current)) {
/* $FlowFixMe[incompatible-return] if `current` is `T` and `T` an array,
* `isArray` might refine to the array element type of `T` */
return current.concat(next);
}

View File

@ -22,6 +22,7 @@ function forEachAccumulated<T>(
scope: ?any,
) {
if (Array.isArray(arr)) {
// $FlowFixMe[incompatible-call] if `T` is an array, `cb` cannot be called
arr.forEach(cb, scope);
} else if (arr) {
cb.call(scope, arr);

View File

@ -476,6 +476,7 @@ export function processUpdateQueue<State>(
hasForceUpdate = false;
if (__DEV__) {
// $FlowFixMe[escaped-generic] discovered when updating Flow
currentlyProcessingQueue = queue.shared;
}

View File

@ -476,6 +476,7 @@ export function processUpdateQueue<State>(
hasForceUpdate = false;
if (__DEV__) {
// $FlowFixMe[escaped-generic] discovered when updating Flow
currentlyProcessingQueue = queue.shared;
}

View File

@ -160,7 +160,7 @@ export type Effect = {
tag: HookFlags,
create: () => (() => void) | void,
destroy: (() => void) | void,
deps: Array<mixed> | null,
deps: Array<mixed> | void | null,
next: Effect,
};
@ -1539,7 +1539,7 @@ function updateStoreInstance<T>(
}
}
function subscribeToStore(fiber, inst, subscribe) {
function subscribeToStore<T>(fiber, inst: StoreInstance<T>, subscribe) {
const handleStoreChange = () => {
// The store changed. Check if the snapshot changed since the last time we
// read from the store.
@ -1552,7 +1552,7 @@ function subscribeToStore(fiber, inst, subscribe) {
return subscribe(handleStoreChange);
}
function checkIfSnapshotChanged(inst) {
function checkIfSnapshotChanged<T>(inst: StoreInstance<T>): boolean {
const latestGetSnapshot = inst.getSnapshot;
const prevValue = inst.value;
try {
@ -1609,7 +1609,7 @@ function rerenderState<S>(
return rerenderReducer(basicStateReducer, (initialState: any));
}
function pushEffect(tag, create, destroy, deps) {
function pushEffect(tag, create, destroy, deps: Array<mixed> | void | null) {
const effect: Effect = {
tag,
create,
@ -1728,7 +1728,12 @@ function updateRef<T>(initialValue: T): {current: T} {
return hook.memoizedState;
}
function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
function mountEffectImpl(
fiberFlags,
hookFlags,
create,
deps: Array<mixed> | void | null,
): void {
const hook = mountWorkInProgressHook();
const nextDeps = deps === undefined ? null : deps;
currentlyRenderingFiber.flags |= fiberFlags;
@ -1740,7 +1745,12 @@ function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
);
}
function updateEffectImpl(fiberFlags, hookFlags, create, deps): void {
function updateEffectImpl(
fiberFlags,
hookFlags,
create,
deps: Array<mixed> | void | null,
): void {
const hook = updateWorkInProgressHook();
const nextDeps = deps === undefined ? null : deps;
let destroy = undefined;
@ -2395,7 +2405,7 @@ function entangleTransitionUpdate<S, A>(
}
}
function markUpdateInDevTools(fiber, lane, action) {
function markUpdateInDevTools<A>(fiber, lane, action: A) {
if (__DEV__) {
if (enableDebugTracing) {
if (fiber.mode & DebugTracingMode) {
@ -2490,6 +2500,7 @@ const HooksDispatcherOnMount: Dispatcher = {
if (enableCache) {
(HooksDispatcherOnMount: Dispatcher).getCacheSignal = getCacheSignal;
(HooksDispatcherOnMount: Dispatcher).getCacheForType = getCacheForType;
// $FlowFixMe[escaped-generic] discovered when updating Flow
(HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
}
if (enableUseHook) {

View File

@ -160,7 +160,7 @@ export type Effect = {
tag: HookFlags,
create: () => (() => void) | void,
destroy: (() => void) | void,
deps: Array<mixed> | null,
deps: Array<mixed> | void | null,
next: Effect,
};
@ -1539,7 +1539,7 @@ function updateStoreInstance<T>(
}
}
function subscribeToStore(fiber, inst, subscribe) {
function subscribeToStore<T>(fiber, inst: StoreInstance<T>, subscribe) {
const handleStoreChange = () => {
// The store changed. Check if the snapshot changed since the last time we
// read from the store.
@ -1552,7 +1552,7 @@ function subscribeToStore(fiber, inst, subscribe) {
return subscribe(handleStoreChange);
}
function checkIfSnapshotChanged(inst) {
function checkIfSnapshotChanged<T>(inst: StoreInstance<T>): boolean {
const latestGetSnapshot = inst.getSnapshot;
const prevValue = inst.value;
try {
@ -1609,7 +1609,7 @@ function rerenderState<S>(
return rerenderReducer(basicStateReducer, (initialState: any));
}
function pushEffect(tag, create, destroy, deps) {
function pushEffect(tag, create, destroy, deps: Array<mixed> | void | null) {
const effect: Effect = {
tag,
create,
@ -1728,7 +1728,12 @@ function updateRef<T>(initialValue: T): {current: T} {
return hook.memoizedState;
}
function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
function mountEffectImpl(
fiberFlags,
hookFlags,
create,
deps: Array<mixed> | void | null,
): void {
const hook = mountWorkInProgressHook();
const nextDeps = deps === undefined ? null : deps;
currentlyRenderingFiber.flags |= fiberFlags;
@ -1740,7 +1745,12 @@ function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
);
}
function updateEffectImpl(fiberFlags, hookFlags, create, deps): void {
function updateEffectImpl(
fiberFlags,
hookFlags,
create,
deps: Array<mixed> | void | null,
): void {
const hook = updateWorkInProgressHook();
const nextDeps = deps === undefined ? null : deps;
let destroy = undefined;
@ -2395,7 +2405,7 @@ function entangleTransitionUpdate<S, A>(
}
}
function markUpdateInDevTools(fiber, lane, action) {
function markUpdateInDevTools<A>(fiber, lane, action: A) {
if (__DEV__) {
if (enableDebugTracing) {
if (fiber.mode & DebugTracingMode) {
@ -2490,6 +2500,7 @@ const HooksDispatcherOnMount: Dispatcher = {
if (enableCache) {
(HooksDispatcherOnMount: Dispatcher).getCacheSignal = getCacheSignal;
(HooksDispatcherOnMount: Dispatcher).getCacheForType = getCacheForType;
// $FlowFixMe[escaped-generic] discovered when updating Flow
(HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
}
if (enableUseHook) {

View File

@ -654,6 +654,7 @@ export function createSignatureFunctionForTransform() {
// in HOC chains like _s(hoc1(_s(hoc2(_s(actualFunction))))).
if (!savedType) {
// We're in the innermost call, so this is the actual type.
// $FlowFixMe[escaped-generic] discovered when updating Flow
savedType = type;
hasCustomHooks = typeof getCustomHooks === 'function';
}

View File

@ -8,6 +8,7 @@
*/
import type {ReactModel} from 'react-server/src/ReactFlightServer';
import type {Destination} from 'react-server/src/ReactServerStreamConfigNode';
import type {BundlerConfig} from './ReactFlightServerWebpackBundlerConfig';
import type {Writable} from 'stream';
import type {ServerContextJSONValue} from 'shared/ReactTypes';
@ -19,7 +20,7 @@ import {
abort,
} from 'react-server/src/ReactFlightServer';
function createDrainHandler(destination, request) {
function createDrainHandler(destination: Destination, request) {
return () => startFlowing(request, destination);
}

View File

@ -128,7 +128,10 @@ export function useSyncExternalStore<T>(
return value;
}
function checkIfSnapshotChanged(inst) {
function checkIfSnapshotChanged<T>(inst: {
value: T,
getSnapshot: () => T,
}): boolean {
const latestGetSnapshot = inst.getSnapshot;
const prevValue = inst.value;
try {

View File

@ -45,9 +45,10 @@ esproposal.class_instance_fields=enable
esproposal.optional_chaining=enable
exact_by_default=true
munge_underscores=false
types_first=false
# Substituted by createFlowConfig.js:
%REACT_RENDERER_FLOW_OPTIONS%
[version]
^0.132.0
^0.140.0

View File

@ -7914,10 +7914,10 @@ flatted@^2.0.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==
flow-bin@^0.132:
version "0.132.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.132.0.tgz#8bf80a79630db24bd1422dc2cc4b5e97f97ccb98"
integrity sha512-S1g/vnAyNaLUdajmuUHCMl30qqye12gS6mr4LVyswf1k+JDF4efs6SfKmptuvnpitF3LGCVf0TIffChP8ljwnw==
flow-bin@^0.140:
version "0.140.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.140.0.tgz#bf1a2984a0e5604daa0d1e0432138d9897af65bb"
integrity sha512-9P/VciKACXocClhLiDg/p1ntYmgCEEc9QrNOoTqTi2SEdEZDTiAmJLONRJfw4uglPVRZ1p/esWF9KlbZiuxqVw==
fluent-syntax@0.13.0:
version "0.13.0"