Skip to content

Commit e706721

Browse files
authored
Update Flow to 0.84 (#17805)
* Update Flow to 0.84 * Fix violations * Use inexact object syntax in files from fbsource * Fix warning extraction to use a modern parser * Codemod inexact objects to new syntax * Tighten types that can be exact * Revert unintentional formatting changes from codemod
1 parent b979db4 commit e706721

File tree

97 files changed

+313
-233
lines changed

Some content is hidden

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

97 files changed

+313
-233
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@babel/code-frame": "^7.0.0",
99
"@babel/core": "^7.0.0",
1010
"@babel/helper-module-imports": "^7.0.0",
11+
"@babel/parser": "^7.0.0",
1112
"@babel/plugin-external-helpers": "^7.0.0",
1213
"@babel/plugin-proposal-class-properties": "^7.0.0",
1314
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
@@ -36,7 +37,6 @@
3637
"art": "^0.10.1",
3738
"babel-eslint": "^10.0.0",
3839
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
39-
"babylon": "6.18.0",
4040
"chalk": "^1.1.3",
4141
"cli-table": "^0.3.1",
4242
"coffee-script": "^1.8.0",
@@ -56,7 +56,7 @@
5656
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
5757
"fbjs-scripts": "^0.8.3",
5858
"filesize": "^3.5.6",
59-
"flow-bin": "^0.72.0",
59+
"flow-bin": "^0.84.0",
6060
"glob": "^6.0.4",
6161
"glob-stream": "^6.1.0",
6262
"google-closure-compiler": "20190301.0.0",

packages/create-subscription/src/createSubscription.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export function createSubscription<Property, Value>(
2929
callback: (value: Value | void) => void,
3030
) => Unsubscribe,
3131
|}>,
32-
): React$ComponentType<{
32+
): React$ComponentType<{|
3333
children: (value: Value | void) => React$Node,
3434
source: Property,
35-
}> {
35+
|}> {
3636
const {getCurrentValue, subscribe} = config;
3737

3838
if (__DEV__) {
@@ -44,14 +44,14 @@ export function createSubscription<Property, Value>(
4444
}
4545
}
4646

47-
type Props = {
47+
type Props = {|
4848
children: (value: Value) => React$Element<any>,
4949
source: Property,
50-
};
51-
type State = {
50+
|};
51+
type State = {|
5252
source: Property,
5353
value: Value | void,
54-
};
54+
|};
5555

5656
// Reference: https://gist.github.com/bvaughn/d569177d70b50b58bff69c3c4a5353f3
5757
class Subscription extends React.Component<Props, State> {

packages/legacy-events/EventPluginRegistry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616

1717
import invariant from 'shared/invariant';
1818

19-
type NamesToPlugins = {[key: PluginName]: PluginModule<AnyNativeEvent>};
19+
type NamesToPlugins = {[key: PluginName]: PluginModule<AnyNativeEvent>, ...};
2020
type EventPluginOrder = null | Array<PluginName>;
2121

2222
/**

packages/legacy-events/PluginModuleType.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
import type {TopLevelType} from './TopLevelEventTypes';
1616
import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
1717

18-
export type EventTypes = {[key: string]: DispatchConfig};
18+
export type EventTypes = {[key: string]: DispatchConfig, ...};
1919

2020
export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch;
2121

@@ -31,4 +31,5 @@ export type PluginModule<NativeEvent> = {
3131
eventSystemFlags: EventSystemFlags,
3232
) => ?ReactSyntheticEvent,
3333
tapMoveThreshold?: number,
34+
...
3435
};

packages/legacy-events/ReactSyntheticEventType.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import type {Fiber} from 'react-reconciler/src/ReactFiber';
1212
import type {EventPriority} from 'shared/ReactTypes';
1313
import type {TopLevelType} from './TopLevelEventTypes';
1414

15-
export type DispatchConfig = {
15+
export type DispatchConfig = {|
1616
dependencies: Array<TopLevelType>,
17-
phasedRegistrationNames?: {
17+
phasedRegistrationNames?: {|
1818
bubbled: string,
1919
captured: string,
20-
},
20+
|},
2121
registrationName?: string,
2222
eventPriority: EventPriority,
23-
};
23+
|};
2424

25-
export type ReactSyntheticEvent = {
25+
export type ReactSyntheticEvent = {|
2626
dispatchConfig: DispatchConfig,
2727
getPooled: (
2828
dispatchConfig: DispatchConfig,
@@ -31,4 +31,4 @@ export type ReactSyntheticEvent = {
3131
nativeEventTarget: EventTarget,
3232
) => ReactSyntheticEvent,
3333
isPersistent: () => boolean,
34-
} & SyntheticEvent<>;
34+
|} & SyntheticEvent<>;

packages/legacy-events/ResponderTouchHistoryStore.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {isStartish, isMoveish, isEndish} from './ResponderTopLevelEventTypes';
1616
* should typically only see IDs in the range of 1-20 because IDs get recycled
1717
* when touches end and start again.
1818
*/
19-
type TouchRecord = {
19+
type TouchRecord = {|
2020
touchActive: boolean,
2121
startPageX: number,
2222
startPageY: number,
@@ -27,7 +27,7 @@ type TouchRecord = {
2727
previousPageX: number,
2828
previousPageY: number,
2929
previousTimeStamp: number,
30-
};
30+
|};
3131

3232
const MAX_TOUCH_BANK = 20;
3333
const touchBank: Array<TouchRecord> = [];
@@ -46,10 +46,12 @@ type Touch = {
4646
pageX: number,
4747
pageY: number,
4848
timestamp: number,
49+
...
4950
};
5051
type TouchEvent = {
5152
changedTouches: Array<Touch>,
5253
touches: Array<Touch>,
54+
...
5355
};
5456

5557
function timestampForTouch(touch: Touch): number {

packages/react-cache/src/ReactCache.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ import {createLRU} from './LRU';
1313

1414
type Thenable<T> = {
1515
then(resolve: (T) => mixed, reject: (mixed) => mixed): mixed,
16+
...
1617
};
1718

18-
type Suspender = {
19-
then(resolve: () => mixed, reject: () => mixed): mixed,
20-
};
19+
type Suspender = {then(resolve: () => mixed, reject: () => mixed): mixed, ...};
2120

2221
type PendingResult = {|
2322
status: 0,
@@ -39,6 +38,7 @@ type Result<V> = PendingResult | ResolvedResult<V> | RejectedResult;
3938
type Resource<I, V> = {
4039
read(I): V,
4140
preload(I): void,
41+
...
4242
};
4343

4444
const Pending = 0;

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type HookLogEntry = {
3636
primitive: string,
3737
stackError: Error,
3838
value: mixed,
39+
...
3940
};
4041

4142
let hookLog: Array<HookLogEntry> = [];
@@ -142,7 +143,7 @@ function useReducer<S, I, A>(
142143
return [state, (action: A) => {}];
143144
}
144145

145-
function useRef<T>(initialValue: T): {current: T} {
146+
function useRef<T>(initialValue: T): {|current: T|} {
146147
let hook = nextHook();
147148
let ref = hook !== null ? hook.memoizedState : {current: initialValue};
148149
hookLog.push({
@@ -174,7 +175,7 @@ function useEffect(
174175
}
175176

176177
function useImperativeHandle<T>(
177-
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
178+
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
178179
create: () => T,
179180
inputs: Array<mixed> | void | null,
180181
): void {
@@ -285,6 +286,7 @@ export type HooksNode = {
285286
name: string,
286287
value: mixed,
287288
subHooks: Array<HooksNode>,
289+
...
288290
};
289291
export type HooksTree = Array<HooksNode>;
290292

packages/react-devtools-core/src/backend.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type ConnectOptions = {
2727
resolveRNStyle?: ResolveNativeStyle,
2828
isAppActive?: () => boolean,
2929
websocket?: ?WebSocket,
30+
...
3031
};
3132

3233
installHook(window);
@@ -120,7 +121,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
120121
});
121122
bridge.addListener(
122123
'inspectElement',
123-
({id, rendererID}: {id: number, rendererID: number}) => {
124+
({id, rendererID}: {id: number, rendererID: number, ...}) => {
124125
const renderer = agent.rendererInterfaces[rendererID];
125126
if (renderer != null) {
126127
// Send event for RN to highlight.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default class Agent extends EventEmitter<{|
109109
_bridge: BackendBridge;
110110
_isProfiling: boolean = false;
111111
_recordChangeDescriptions: boolean = false;
112-
_rendererInterfaces: {[key: RendererID]: RendererInterface} = {};
112+
_rendererInterfaces: {[key: RendererID]: RendererInterface, ...} = {};
113113
_persistedSelection: PersistedSelection | null = null;
114114
_persistedSelectionMatch: PathMatch | null = null;
115115
_traceUpdatesEnabled: boolean = false;
@@ -185,7 +185,7 @@ export default class Agent extends EventEmitter<{|
185185
setupTraceUpdates(this);
186186
}
187187

188-
get rendererInterfaces(): {[key: RendererID]: RendererInterface} {
188+
get rendererInterfaces(): {[key: RendererID]: RendererInterface, ...} {
189189
return this._rendererInterfaces;
190190
}
191191

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function initBackend(
3030
id: number,
3131
renderer: ReactRenderer,
3232
rendererInterface: RendererInterface,
33+
...
3334
}) => {
3435
agent.setRendererInterface(id, rendererInterface);
3536

@@ -91,7 +92,7 @@ export function initBackend(
9192
subs.push(
9293
hook.sub(
9394
'renderer',
94-
({id, renderer}: {id: number, renderer: ReactRenderer}) => {
95+
({id, renderer}: {id: number, renderer: ReactRenderer, ...}) => {
9596
attachRenderer(id, renderer);
9697
},
9798
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function decorate(object: Object, attr: string, fn: Function): Function {
1919

2020
export function decorateMany(
2121
source: Object,
22-
fns: {[attr: string]: Function},
22+
fns: {[attr: string]: Function, ...},
2323
): Object {
2424
const olds = {};
2525
for (const name in fns) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import type {
7676
type getDisplayNameForFiberType = (fiber: Fiber) => string | null;
7777
type getTypeSymbolType = (type: any) => Symbol | number;
7878

79-
type ReactSymbolsType = {
79+
type ReactSymbolsType = {|
8080
CONCURRENT_MODE_NUMBER: number,
8181
CONCURRENT_MODE_SYMBOL_STRING: string,
8282
DEPRECATED_ASYNC_MODE_SYMBOL_STRING: string,
@@ -94,7 +94,7 @@ type ReactSymbolsType = {
9494
STRICT_MODE_SYMBOL_STRING: string,
9595
SCOPE_NUMBER: number,
9696
SCOPE_SYMBOL_STRING: string,
97-
};
97+
|};
9898

9999
type ReactPriorityLevelsType = {|
100100
ImmediatePriority: number,

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,44 +48,39 @@ export type FindNativeNodesForFiberID = (id: number) => ?Array<NativeType>;
4848
export type ReactProviderType<T> = {
4949
$$typeof: Symbol | number,
5050
_context: ReactContext<T>,
51+
...
5152
};
5253

5354
export type ReactRenderer = {
5455
findFiberByHostInstance: (hostInstance: NativeType) => ?Fiber,
5556
version: string,
5657
bundleType: BundleType,
57-
5858
// 16.9+
5959
overrideHookState?: ?(
6060
fiber: Object,
6161
id: number,
6262
path: Array<string | number>,
6363
value: any,
6464
) => void,
65-
6665
// 16.7+
6766
overrideProps?: ?(
6867
fiber: Object,
6968
path: Array<string | number>,
7069
value: any,
7170
) => void,
72-
7371
// 16.9+
7472
scheduleUpdate?: ?(fiber: Object) => void,
7573
setSuspenseHandler?: ?(shouldSuspend: (fiber: Object) => boolean) => void,
76-
7774
// Only injected by React v16.8+ in order to support hooks inspection.
7875
currentDispatcherRef?: {|current: null | Dispatcher|},
79-
8076
// Only injected by React v16.9+ in DEV mode.
8177
// Enables DevTools to append owners-only component stack to error messages.
8278
getCurrentFiber?: () => Fiber | null,
83-
8479
// Uniquely identifies React DOM v15.
8580
ComponentTree?: any,
86-
8781
// Present for React DOM v12 (possibly earlier) through v15.
8882
Mount?: any,
83+
...
8984
};
9085

9186
export type ChangeDescription = {|
@@ -267,12 +262,13 @@ export type RendererInterface = {
267262
count: number,
268263
) => void,
269264
updateComponentFilters: (componentFilters: Array<ComponentFilter>) => void,
265+
...
270266
};
271267

272268
export type Handler = (data: any) => void;
273269

274270
export type DevToolsHook = {
275-
listeners: {[key: string]: Array<Handler>},
271+
listeners: {[key: string]: Array<Handler>, ...},
276272
rendererInterfaces: Map<RendererID, RendererInterface>,
277273
renderers: Map<RendererID, ReactRenderer>,
278274

@@ -299,4 +295,5 @@ export type DevToolsHook = {
299295
// Added in v16.9 to support Fast Refresh
300296
didError?: boolean,
301297
) => void,
298+
...
302299
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export default function setupHighlighter(
9595
openNativeElementsPanel: boolean,
9696
rendererID: number,
9797
scrollIntoView: boolean,
98+
...
9899
}) {
99100
const renderer = agent.rendererInterfaces[rendererID];
100101
if (renderer == null) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type Rect = {
1414
right: number,
1515
top: number,
1616
width: number,
17+
...
1718
};
1819

1920
// Get the window object for the document that a node belongs to,

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ import React, {createContext} from 'react';
2121

2222
export type Thenable<T> = {
2323
then(resolve: (T) => mixed, reject: (mixed) => mixed): mixed,
24+
...
2425
};
2526

26-
type Suspender = {
27-
then(resolve: () => mixed, reject: () => mixed): mixed,
28-
};
27+
type Suspender = {then(resolve: () => mixed, reject: () => mixed): mixed, ...};
2928

3029
type PendingResult = {|
3130
status: 0,
@@ -50,6 +49,7 @@ export type Resource<Input, Key, Value> = {
5049
read(Input): Value,
5150
preload(Input): void,
5251
write(Key, Value): void,
52+
...
5353
};
5454

5555
const Pending = 0;
@@ -73,9 +73,7 @@ function readContext(Context, observedBits) {
7373

7474
const CacheContext = createContext(null);
7575

76-
type Config = {
77-
useWeakMap?: boolean,
78-
};
76+
type Config = {useWeakMap?: boolean, ...};
7977

8078
const entries: Map<
8179
Resource<any, any, any>,

0 commit comments

Comments
 (0)