Skip to content

Commit 9f8a98a

Browse files
committed
Flow upgrade to 0.153
- method unbinding is no longer supported in Flow for soundness, this added a bunch of suppressions - Flow now prevents objects to be supertypes of interfaces/classes ghstack-source-id: d7749cb Pull Request resolved: #25412
1 parent adb58f5 commit 9f8a98a

Some content is hidden

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

52 files changed

+110
-38
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.152.0",
66+
"flow-bin": "^0.153.0",
6767
"glob": "^7.1.6",
6868
"glob-stream": "^6.1.0",
6969
"google-closure-compiler": "^20200517.0.0",

packages/jest-react/src/internalAct.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
7272
if (
7373
typeof result === 'object' &&
7474
result !== null &&
75+
// $FlowFixMe[method-unbinding]
7576
typeof result.then === 'function'
7677
) {
7778
const thenableResult: Thenable<T> = (result: any);

packages/react-cache/src/ReactCacheOld.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import * as React from 'react';
1313

1414
import {createLRU} from './LRU';
1515

16-
type Suspender = {then(resolve: () => mixed, reject: () => mixed): mixed, ...};
16+
interface Suspender {
17+
then(resolve: () => mixed, reject: () => mixed): mixed;
18+
}
1719

1820
type PendingResult = {
1921
status: 0,
@@ -120,6 +122,7 @@ function accessResult<I, K, V>(
120122
);
121123
const newResult: PendingResult = {
122124
status: Pending,
125+
// $FlowFixMe[method-unbinding]
123126
value: thenable,
124127
};
125128
// $FlowFixMe[escaped-generic] discovered when updating Flow

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ import {__PERFORMANCE_PROFILE__} from './constants';
1111

1212
const supportsUserTiming =
1313
typeof performance !== 'undefined' &&
14+
// $FlowFixMe[method-unbinding]
1415
typeof performance.mark === 'function' &&
16+
// $FlowFixMe[method-unbinding]
1517
typeof performance.clearMarks === 'function';
1618

1719
const supportsPerformanceNow =
20+
// $FlowFixMe[method-unbinding]
1821
typeof performance !== 'undefined' && typeof performance.now === 'function';
1922

2023
function mark(markName: string): void {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ let performanceTarget: Performance | null = null;
4444
// If performance exists and supports the subset of the User Timing API that we require.
4545
let supportsUserTiming =
4646
typeof performance !== 'undefined' &&
47+
// $FlowFixMe[method-unbinding]
4748
typeof performance.mark === 'function' &&
49+
// $FlowFixMe[method-unbinding]
4850
typeof performance.clearMarks === 'function';
4951

5052
let supportsUserTimingV3 = false;
@@ -76,6 +78,7 @@ if (supportsUserTimingV3) {
7678

7779
// Some environments (e.g. React Native / Hermes) don't support the performance API yet.
7880
const getCurrentTime =
81+
// $FlowFixMe[method-unbinding]
7982
typeof performance === 'object' && typeof performance.now === 'function'
8083
? () => performance.now()
8184
: () => Date.now();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ function getFiberFlags(fiber: Fiber): number {
151151

152152
// Some environments (e.g. React Native / Hermes) don't support the performance API yet.
153153
const getCurrentTime =
154+
// $FlowFixMe[method-unbinding]
154155
typeof performance === 'object' && typeof performance.now === 'function'
155156
? () => performance.now()
156157
: () => Date.now();

packages/react-devtools-shared/src/backend/views/Highlighter/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default function setupHighlighter(
115115

116116
if (nodes != null && nodes[0] != null) {
117117
const node = nodes[0];
118+
// $FlowFixMe[method-unbinding]
118119
if (scrollIntoView && typeof node.scrollIntoView === 'function') {
119120
// If the node isn't visible show it before highlighting it.
120121
// We may want to reconsider this; it might be a little disruptive.

packages/react-devtools-shared/src/backend/views/TraceUpdates/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const REMEASUREMENT_AFTER_DURATION = 250;
2626

2727
// Some environments (e.g. React Native / Hermes) don't support the performance API yet.
2828
const getCurrentTime =
29+
// $FlowFixMe[method-unbinding]
2930
typeof performance === 'object' && typeof performance.now === 'function'
3031
? () => performance.now()
3132
: () => Date.now();

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
* @flow
88
*/
99

10-
export type Rect = {
11-
bottom: number,
12-
height: number,
13-
left: number,
14-
right: number,
15-
top: number,
16-
width: number,
17-
...
18-
};
10+
export interface Rect {
11+
bottom: number;
12+
height: number;
13+
left: number;
14+
right: number;
15+
top: number;
16+
width: number;
17+
}
1918

2019
// Get the window object for the document that a node belongs to,
2120
// or return null if it cannot be found (node not attached to DOM,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import {createContext} from 'react';
2626

2727
export type {Thenable};
2828

29-
type Suspender = {then(resolve: () => mixed, reject: () => mixed): mixed, ...};
29+
interface Suspender {
30+
then(resolve: () => mixed, reject: () => mixed): mixed;
31+
}
3032

3133
type PendingResult = {
3234
status: 0,
@@ -124,6 +126,7 @@ function accessResult<Input, Key, Value>(
124126
);
125127
const newResult: PendingResult = {
126128
status: Pending,
129+
// $FlowFixMe[method-unbinding]
127130
value: thenable,
128131
};
129132
entriesForResource.set(key, newResult);

packages/react-devtools-shared/src/devtools/views/Components/KeyValue.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {Element} from 'react-devtools-shared/src/devtools/views/Components/
3333
import type {Element as ReactElement} from 'react';
3434
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
3535

36+
// $FlowFixMe[method-unbinding]
3637
const hasOwnProperty = Object.prototype.hasOwnProperty;
3738

3839
type Type = 'props' | 'state' | 'context' | 'hooks';

packages/react-devtools-shared/src/devtools/views/Profiler/SidebarSelectedFiberInfo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export default function SidebarSelectedFiberInfo(_: Props): React.Node {
6767
const selectedElement = selectedListItemRef.current;
6868
if (
6969
selectedElement !== null &&
70+
// $FlowFixMe[method-unbinding]
7071
typeof selectedElement.scrollIntoView === 'function'
7172
) {
7273
selectedElement.scrollIntoView({block: 'nearest', inline: 'nearest'});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import isArray from 'react-devtools-shared/src/isArray';
1414

1515
import type {HooksTree} from 'react-debug-tools/src/ReactDebugHooks';
1616

17+
// $FlowFixMe[method-unbinding]
1718
const hasOwnProperty = Object.prototype.hasOwnProperty;
1819

1920
export function alphaSortEntries(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function installHook(target: any): DevToolsHook | null {
6161
// it happens *outside* of the renderer injection. See `checkDCE` below.
6262
}
6363

64+
// $FlowFixMe[method-unbinding]
6465
const toString = Function.prototype.toString;
6566
if (renderer.Mount && renderer.Mount._renderNewRootComponent) {
6667
// React DOM Stack
@@ -147,6 +148,7 @@ export function installHook(target: any): DevToolsHook | null {
147148
// This runs for production versions of React.
148149
// Needs to be super safe.
149150
try {
151+
// $FlowFixMe[method-unbinding]
150152
const toString = Function.prototype.toString;
151153
const code = toString.call(fn);
152154

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import isArray from './isArray';
5656
import type {ComponentFilter, ElementType} from './types';
5757
import type {LRUCache} from 'react-devtools-shared/src/types';
5858

59+
// $FlowFixMe[method-unbinding]
5960
const hasOwnProperty = Object.prototype.hasOwnProperty;
6061

6162
const cachedDisplayNames: WeakMap<Function, string> = new WeakMap();
@@ -598,6 +599,7 @@ export function getDataType(data: Object): DataType {
598599
} else if (data.constructor && data.constructor.name === 'RegExp') {
599600
return 'regexp';
600601
} else {
602+
// $FlowFixMe[method-unbinding]
601603
const toStringValue = Object.prototype.toString.call(data);
602604
if (toStringValue === '[object Date]') {
603605
return 'date';
@@ -612,6 +614,7 @@ export function getDataType(data: Object): DataType {
612614
return 'symbol';
613615
case 'undefined':
614616
if (
617+
// $FlowFixMe[method-unbinding]
615618
Object.prototype.toString.call(data) === '[object HTMLAllCollection]'
616619
) {
617620
return 'html_all_collection';

packages/react-devtools-timeline/src/import-worker/preprocessData.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,11 @@ function preprocessFlamechart(rawData: TimelineEvent[]): Flamechart {
968968
const profile = parsedData.profiles[0]; // TODO: Choose the main CPU thread only
969969

970970
const speedscopeFlamechart = new SpeedscopeFlamechart({
971+
// $FlowFixMe[method-unbinding]
971972
getTotalWeight: profile.getTotalWeight.bind(profile),
973+
// $FlowFixMe[method-unbinding]
972974
forEachCall: profile.forEachCall.bind(profile),
975+
// $FlowFixMe[method-unbinding]
973976
formatValue: profile.formatValue.bind(profile),
974977
getColorBucketForFrame: () => 0,
975978
});

packages/react-dom-bindings/src/client/ReactDOMComponent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ export function createElement(
455455
if (namespaceURI === HTML_NAMESPACE) {
456456
if (
457457
!isCustomComponentTag &&
458+
// $FlowFixMe[method-unbinding]
458459
Object.prototype.toString.call(domElement) ===
459460
'[object HTMLUnknownElement]' &&
460461
!hasOwnProperty.call(warnedUnknownTags, type)

packages/react-dom-bindings/src/client/ReactDOMComponentTree.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ export function precacheFiberNode(
6161
}
6262

6363
export function markContainerAsRoot(hostRoot: Fiber, node: Container): void {
64+
// $FlowFixMe[prop-missing]
6465
node[internalContainerInstanceKey] = hostRoot;
6566
}
6667

6768
export function unmarkContainerAsRoot(node: Container): void {
69+
// $FlowFixMe[prop-missing]
6870
node[internalContainerInstanceKey] = null;
6971
}
7072

7173
export function isContainerMarkedAsRoot(node: Container): boolean {
74+
// $FlowFixMe[prop-missing]
7275
return !!node[internalContainerInstanceKey];
7376
}
7477

@@ -132,6 +135,7 @@ export function getClosestInstanceFromNode(targetNode: Node): null | Fiber {
132135
// have had an internalInstanceKey on it.
133136
// Let's get the fiber associated with the SuspenseComponent
134137
// as the deepest instance.
138+
// $FlowFixMe[prop-missing]
135139
const targetSuspenseInst = suspenseInstance[internalInstanceKey];
136140
if (targetSuspenseInst) {
137141
return targetSuspenseInst;

packages/react-dom-bindings/src/client/ReactDOMHostConfig.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ export type EventTargetChildElement = {
117117
...
118118
};
119119
export type Container =
120-
| (Element & {_reactRootContainer?: FiberRoot, ...})
121-
| (Document & {_reactRootContainer?: FiberRoot, ...})
122-
| (DocumentFragment & {_reactRootContainer?: FiberRoot, ...});
120+
| interface extends Element {_reactRootContainer?: FiberRoot}
121+
| interface extends Document {_reactRootContainer?: FiberRoot}
122+
| interface extends DocumentFragment {_reactRootContainer?: FiberRoot};
123123
export type Instance = Element;
124124
export type TextInstance = Text;
125-
export type SuspenseInstance = Comment & {_reactRetry?: () => void, ...};
125+
export interface SuspenseInstance extends Comment {
126+
_reactRetry?: () => void;
127+
}
126128
export type HydratableInstance = Instance | TextInstance | SuspenseInstance;
127129
export type PublicInstance = Element | Text;
128130
type HostContextDev = {
@@ -644,6 +646,7 @@ export function hideInstance(instance: Instance): void {
644646
// pass host context to this method?
645647
instance = ((instance: any): HTMLElement);
646648
const style = instance.style;
649+
// $FlowFixMe[method-unbinding]
647650
if (typeof style.setProperty === 'function') {
648651
style.setProperty('display', 'none', 'important');
649652
} else {
@@ -679,6 +682,7 @@ export function clearContainer(container: Container): void {
679682
((container: any): Element).textContent = '';
680683
} else if (container.nodeType === DOCUMENT_NODE) {
681684
if (container.documentElement) {
685+
// $FlowFixMe[incompatible-call]
682686
container.removeChild(container.documentElement);
683687
}
684688
}
@@ -1267,6 +1271,7 @@ export function setFocusIfFocusable(node: Instance): boolean {
12671271
const element = ((node: any): HTMLElement);
12681272
try {
12691273
element.addEventListener('focus', handleFocus);
1274+
// $FlowFixMe[method-unbinding]
12701275
(element.focus || HTMLElement.prototype.focus).call(element);
12711276
} finally {
12721277
element.removeEventListener('focus', handleFocus);
@@ -1349,11 +1354,13 @@ export const supportsResources = true;
13491354
export {isHostResourceType};
13501355
function isHostResourceInstance(instance: Instance | Container): boolean {
13511356
if (instance.nodeType === ELEMENT_NODE) {
1357+
// $FlowFixMe[prop-missing] Flow doesn't understand `nodeType` test.
13521358
switch (instance.tagName.toLowerCase()) {
13531359
case 'link': {
13541360
const rel = ((instance: any): HTMLLinkElement).rel;
13551361
return (
13561362
rel === 'preload' ||
1363+
// $FlowFixMe[prop-missing] Flow doesn't understand `nodeType` test.
13571364
(rel === 'stylesheet' && instance.hasAttribute('data-rprec'))
13581365
);
13591366
}

packages/react-dom-bindings/src/client/ReactDOMSelect.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ function updateOptions(
7373
propValue: any,
7474
setDefaultSelected: boolean,
7575
) {
76-
type IndexableHTMLOptionsCollection = HTMLOptionsCollection & {
77-
[key: number]: HTMLOptionElement,
78-
...,
79-
};
80-
const options: IndexableHTMLOptionsCollection = node.options;
76+
const options: HTMLOptionsCollection = node.options;
8177

8278
if (multiple) {
8379
const selectedValues = (propValue: Array<string>);

packages/react-dom-bindings/src/client/inputValueTracking.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ type ValueTracker = {
1414
setValue(value: string): void,
1515
stopTracking(): void,
1616
};
17-
type WrapperState = {_valueTracker?: ?ValueTracker, ...};
18-
type ElementWithValueTracker = HTMLInputElement & WrapperState;
17+
interface ElementWithValueTracker extends HTMLInputElement {
18+
_valueTracker?: ?ValueTracker;
19+
}
1920

2021
function isCheckable(elem: HTMLInputElement) {
2122
const type = elem.type;

packages/react-dom-bindings/src/events/DOMPluginEventSystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ export function accumulateSinglePhaseListeners(
761761
// current instance fiber. In which case, we should clear all existing
762762
// listeners.
763763
if (enableCreateEventHandleAPI && nativeEvent.type === 'beforeblur') {
764-
// $FlowFixMe: internal field
764+
// $FlowFixMe[prop-missing] internal field
765765
const detachedInterceptFiber = nativeEvent._detachedInterceptFiber;
766766
if (
767767
detachedInterceptFiber !== null &&

packages/react-dom-bindings/src/server/ReactDOMLegacyServerStreamConfig.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
* @flow
88
*/
99

10-
export type Destination = {
11-
push(chunk: string | null): boolean,
12-
destroy(error: Error): mixed,
13-
...
14-
};
10+
export interface Destination {
11+
push(chunk: string | null): boolean;
12+
destroy(error: Error): mixed;
13+
}
1514

1615
export type PrecomputedChunk = string;
1716
export type Chunk = string;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ function legacyCreateRootFromDOMContainer(
145145

146146
const rootContainerElement =
147147
container.nodeType === COMMENT_NODE ? container.parentNode : container;
148+
// $FlowFixMe[incompatible-call]
148149
listenToAllSupportedEvents(rootContainerElement);
149150

150151
flushSync();
@@ -179,6 +180,7 @@ function legacyCreateRootFromDOMContainer(
179180

180181
const rootContainerElement =
181182
container.nodeType === COMMENT_NODE ? container.parentNode : container;
183+
// $FlowFixMe[incompatible-call]
182184
listenToAllSupportedEvents(rootContainerElement);
183185

184186
// Initial mount should not be batched.
@@ -435,6 +437,8 @@ export function unmountComponentAtNode(container: Container): boolean {
435437
const isContainerReactRoot =
436438
container.nodeType === ELEMENT_NODE &&
437439
isValidContainerLegacy(container.parentNode) &&
440+
// $FlowFixMe[prop-missing]
441+
// $FlowFixMe[incompatible-use]
438442
!!container.parentNode._reactRootContainer;
439443

440444
if (hasNonRootReactChild) {

packages/react-native-renderer/src/ReactFabricEventEmitter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export function dispatchEvent(
115115
// Note that extracted events are *not* emitted,
116116
// only events that have a 1:1 mapping with a native event, at least for now.
117117
const event = {eventName: topLevelType, nativeEvent};
118+
// $FlowFixMe[class-object-subtyping] found when upgrading Flow
118119
RawEventEmitter.emit(topLevelType, event);
119120
RawEventEmitter.emit('*', event);
120121

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ class ReactFabricHostComponent {
316316
}
317317

318318
// eslint-disable-next-line no-unused-expressions
319+
// $FlowFixMe[class-object-subtyping] found when upgrading Flow
319320
(ReactFabricHostComponent.prototype: $ReadOnly<{...NativeMethods, ...}>);
320321

321322
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoMutation';

0 commit comments

Comments
 (0)