Skip to content

Commit e2424f3

Browse files
authored
[flow] enable exact_empty_objects (#25973)
This enables the "exact_empty_objects" setting for Flow which makes empty objects exact instead of building up the type as properties are added in code below. This is in preparation to Flow 191 which makes this the default and removes the config. More about the change in the Flow blog [here](https://medium.com/flow-type/improved-handling-of-the-empty-object-in-flow-ead91887e40c).
1 parent 0b4f443 commit e2424f3

Some content is hidden

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

49 files changed

+182
-135
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,9 @@ function createElement(
393393
// We don't really need to add any of these but keeping them for good measure.
394394
// Unfortunately, _store is enumerable in jest matchers so for equality to
395395
// work, I need to keep it or make _store non-enumerable in the other file.
396-
element._store = {};
396+
element._store = ({}: {
397+
validated?: boolean,
398+
});
397399
Object.defineProperty(element._store, 'validated', {
398400
configurable: false,
399401
enumerable: false,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ function buildTree(
524524
readHookLog: Array<HookLogEntry>,
525525
includeHooksSource: boolean,
526526
): HooksTree {
527-
const rootChildren = [];
527+
const rootChildren: Array<HooksNode> = [];
528528
let prevStack = null;
529529
let levelChildren = rootChildren;
530530
let nativeHookID = 0;
@@ -557,7 +557,7 @@ function buildTree(
557557
// The remaining part of the new stack are custom hooks. Push them
558558
// to the tree.
559559
for (let j = stack.length - commonSteps - 1; j >= 1; j--) {
560-
const children = [];
560+
const children: Array<HooksNode> = [];
561561
const stackFrame = stack[j];
562562
const levelChild: HooksNode = {
563563
id: null,

packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function measureStyle(
170170
}
171171

172172
function shallowClone(object: Object): Object {
173-
const cloned = {};
173+
const cloned: {[string]: $FlowFixMe} = {};
174174
for (const n in object) {
175175
cloned[n] = object[n];
176176
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const injectedRenderers: Map<
7979
> = new Map();
8080

8181
let targetConsole: Object = console;
82-
let targetConsoleMethods = {};
82+
let targetConsoleMethods: {[string]: $FlowFixMe} = {};
8383
for (const method in console) {
8484
targetConsoleMethods[method] = console[method];
8585
}
@@ -97,7 +97,7 @@ export function dangerous_setTargetConsoleForTesting(
9797
): void {
9898
targetConsole = targetConsoleForTesting;
9999

100-
targetConsoleMethods = {};
100+
targetConsoleMethods = ({}: {[string]: $FlowFixMe});
101101
for (const method in targetConsole) {
102102
targetConsoleMethods[method] = console[method];
103103
}
@@ -179,7 +179,7 @@ export function patch({
179179
return;
180180
}
181181

182-
const originalConsoleMethods = {};
182+
const originalConsoleMethods: {[string]: $FlowFixMe} = {};
183183

184184
unpatchFn = () => {
185185
for (const method in originalConsoleMethods) {
@@ -318,7 +318,7 @@ export function patchForStrictMode() {
318318
return;
319319
}
320320

321-
const originalConsoleMethods = {};
321+
const originalConsoleMethods: {[string]: $FlowFixMe} = {};
322322

323323
unpatchForStrictModeFn = () => {
324324
for (const method in originalConsoleMethods) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ export function attach(
785785

786786
let owner = element._owner;
787787
if (owner) {
788-
owners = [];
788+
owners = ([]: Array<SerializedElement>);
789789
while (owner != null) {
790790
owners.push({
791791
displayName: getData(owner).displayName || 'Unknown',
@@ -807,8 +807,8 @@ export function attach(
807807
}
808808

809809
// Not implemented
810-
const errors = [];
811-
const warnings = [];
810+
const errors: Array<[string, number]> = [];
811+
const warnings: Array<[string, number]> = [];
812812

813813
return {
814814
id,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function decorateMany(
2222
source: Object,
2323
fns: {[attr: string]: Function, ...},
2424
): Object {
25-
const olds = {};
25+
const olds: {[string]: $FlowFixMe} = {};
2626
for (const name in fns) {
2727
olds[name] = decorate(source, name, fns[name]);
2828
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ let supportsUserTiming =
5252
let supportsUserTimingV3 = false;
5353
if (supportsUserTiming) {
5454
const CHECK_V3_MARK = '__v3';
55-
const markOptions = {};
55+
const markOptions = ({}: {startTime?: number});
5656
Object.defineProperty(markOptions, 'startTime', {
5757
get: function() {
5858
supportsUserTimingV3 = true;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,7 +3252,7 @@ export function attach(
32523252

32533253
let owners = null;
32543254
if (_debugOwner) {
3255-
owners = [];
3255+
owners = ([]: Array<SerializedElement>);
32563256
let owner: null | Fiber = _debugOwner;
32573257
while (owner !== null) {
32583258
owners.push(fiberToSerializedElement(owner));
@@ -3265,7 +3265,7 @@ export function attach(
32653265

32663266
let hooks = null;
32673267
if (usesHooks) {
3268-
const originalConsoleMethods = {};
3268+
const originalConsoleMethods: {[string]: $FlowFixMe} = {};
32693269

32703270
// Temporarily disable all console logging before re-running the hook.
32713271
for (const method in console) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export function cleanForBridge(
2020
path?: Array<string | number> = [],
2121
): DehydratedData | null {
2222
if (data !== null) {
23-
const cleanedPaths = [];
24-
const unserializablePaths = [];
23+
const cleanedPaths: Array<Array<string | number>> = [];
24+
const unserializablePaths: Array<Array<string | number>> = [];
2525
const cleanedData = dehydrate(
2626
data,
2727
cleanedPaths,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ const STACK_SOURCE_LOCATION = /([^\s]+) \((.+):(.+):(.+)\)/;
198198
export function stackToComponentSources(
199199
stack: string,
200200
): Array<[string, ?Stack]> {
201-
const out = [];
201+
const out: Array<[string, ?Stack]> = [];
202202
stack
203203
.split(STACK_DELIMETER)
204204
.slice(1)

0 commit comments

Comments
 (0)