diff --git a/packages/react-client/src/ReactFlightClient.js b/packages/react-client/src/ReactFlightClient.js index 3c9d26338b660..70e9f5ddaab95 100644 --- a/packages/react-client/src/ReactFlightClient.js +++ b/packages/react-client/src/ReactFlightClient.js @@ -393,7 +393,9 @@ function createElement( // We don't really need to add any of these but keeping them for good measure. // Unfortunately, _store is enumerable in jest matchers so for equality to // work, I need to keep it or make _store non-enumerable in the other file. - element._store = {}; + element._store = ({}: { + validated?: boolean, + }); Object.defineProperty(element._store, 'validated', { configurable: false, enumerable: false, diff --git a/packages/react-debug-tools/src/ReactDebugHooks.js b/packages/react-debug-tools/src/ReactDebugHooks.js index fbe4dc2f360a4..56c6e376dabb6 100644 --- a/packages/react-debug-tools/src/ReactDebugHooks.js +++ b/packages/react-debug-tools/src/ReactDebugHooks.js @@ -524,7 +524,7 @@ function buildTree( readHookLog: Array, includeHooksSource: boolean, ): HooksTree { - const rootChildren = []; + const rootChildren: Array = []; let prevStack = null; let levelChildren = rootChildren; let nativeHookID = 0; @@ -557,7 +557,7 @@ function buildTree( // The remaining part of the new stack are custom hooks. Push them // to the tree. for (let j = stack.length - commonSteps - 1; j >= 1; j--) { - const children = []; + const children: Array = []; const stackFrame = stack[j]; const levelChild: HooksNode = { id: null, diff --git a/packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js b/packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js index ea9b8662f1be2..665a65f292d80 100644 --- a/packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js +++ b/packages/react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor.js @@ -170,7 +170,7 @@ function measureStyle( } function shallowClone(object: Object): Object { - const cloned = {}; + const cloned: {[string]: $FlowFixMe} = {}; for (const n in object) { cloned[n] = object[n]; } diff --git a/packages/react-devtools-shared/src/backend/console.js b/packages/react-devtools-shared/src/backend/console.js index 61ead6d7c478d..ac3d33306ecb4 100644 --- a/packages/react-devtools-shared/src/backend/console.js +++ b/packages/react-devtools-shared/src/backend/console.js @@ -79,7 +79,7 @@ const injectedRenderers: Map< > = new Map(); let targetConsole: Object = console; -let targetConsoleMethods = {}; +let targetConsoleMethods: {[string]: $FlowFixMe} = {}; for (const method in console) { targetConsoleMethods[method] = console[method]; } @@ -97,7 +97,7 @@ export function dangerous_setTargetConsoleForTesting( ): void { targetConsole = targetConsoleForTesting; - targetConsoleMethods = {}; + targetConsoleMethods = ({}: {[string]: $FlowFixMe}); for (const method in targetConsole) { targetConsoleMethods[method] = console[method]; } @@ -179,7 +179,7 @@ export function patch({ return; } - const originalConsoleMethods = {}; + const originalConsoleMethods: {[string]: $FlowFixMe} = {}; unpatchFn = () => { for (const method in originalConsoleMethods) { @@ -318,7 +318,7 @@ export function patchForStrictMode() { return; } - const originalConsoleMethods = {}; + const originalConsoleMethods: {[string]: $FlowFixMe} = {}; unpatchForStrictModeFn = () => { for (const method in originalConsoleMethods) { diff --git a/packages/react-devtools-shared/src/backend/legacy/renderer.js b/packages/react-devtools-shared/src/backend/legacy/renderer.js index 1b667cf122185..69a193ecb08fc 100644 --- a/packages/react-devtools-shared/src/backend/legacy/renderer.js +++ b/packages/react-devtools-shared/src/backend/legacy/renderer.js @@ -785,7 +785,7 @@ export function attach( let owner = element._owner; if (owner) { - owners = []; + owners = ([]: Array); while (owner != null) { owners.push({ displayName: getData(owner).displayName || 'Unknown', @@ -807,8 +807,8 @@ export function attach( } // Not implemented - const errors = []; - const warnings = []; + const errors: Array<[string, number]> = []; + const warnings: Array<[string, number]> = []; return { id, diff --git a/packages/react-devtools-shared/src/backend/legacy/utils.js b/packages/react-devtools-shared/src/backend/legacy/utils.js index bc443c1dd164e..91dc1ff3798fe 100644 --- a/packages/react-devtools-shared/src/backend/legacy/utils.js +++ b/packages/react-devtools-shared/src/backend/legacy/utils.js @@ -22,7 +22,7 @@ export function decorateMany( source: Object, fns: {[attr: string]: Function, ...}, ): Object { - const olds = {}; + const olds: {[string]: $FlowFixMe} = {}; for (const name in fns) { olds[name] = decorate(source, name, fns[name]); } diff --git a/packages/react-devtools-shared/src/backend/profilingHooks.js b/packages/react-devtools-shared/src/backend/profilingHooks.js index 47d173c55c3c4..7f7c766fc45e8 100644 --- a/packages/react-devtools-shared/src/backend/profilingHooks.js +++ b/packages/react-devtools-shared/src/backend/profilingHooks.js @@ -52,7 +52,7 @@ let supportsUserTiming = let supportsUserTimingV3 = false; if (supportsUserTiming) { const CHECK_V3_MARK = '__v3'; - const markOptions = {}; + const markOptions = ({}: {startTime?: number}); Object.defineProperty(markOptions, 'startTime', { get: function() { supportsUserTimingV3 = true; diff --git a/packages/react-devtools-shared/src/backend/renderer.js b/packages/react-devtools-shared/src/backend/renderer.js index 54f95a2fbea6a..d05439e1360af 100644 --- a/packages/react-devtools-shared/src/backend/renderer.js +++ b/packages/react-devtools-shared/src/backend/renderer.js @@ -3252,7 +3252,7 @@ export function attach( let owners = null; if (_debugOwner) { - owners = []; + owners = ([]: Array); let owner: null | Fiber = _debugOwner; while (owner !== null) { owners.push(fiberToSerializedElement(owner)); @@ -3265,7 +3265,7 @@ export function attach( let hooks = null; if (usesHooks) { - const originalConsoleMethods = {}; + const originalConsoleMethods: {[string]: $FlowFixMe} = {}; // Temporarily disable all console logging before re-running the hook. for (const method in console) { diff --git a/packages/react-devtools-shared/src/backend/utils.js b/packages/react-devtools-shared/src/backend/utils.js index 5c0a9d7800bc6..03e7800819af6 100644 --- a/packages/react-devtools-shared/src/backend/utils.js +++ b/packages/react-devtools-shared/src/backend/utils.js @@ -20,8 +20,8 @@ export function cleanForBridge( path?: Array = [], ): DehydratedData | null { if (data !== null) { - const cleanedPaths = []; - const unserializablePaths = []; + const cleanedPaths: Array> = []; + const unserializablePaths: Array> = []; const cleanedData = dehydrate( data, cleanedPaths, diff --git a/packages/react-devtools-shared/src/devtools/utils.js b/packages/react-devtools-shared/src/devtools/utils.js index 2e16d23c989bc..304483fd03f7f 100644 --- a/packages/react-devtools-shared/src/devtools/utils.js +++ b/packages/react-devtools-shared/src/devtools/utils.js @@ -198,7 +198,7 @@ const STACK_SOURCE_LOCATION = /([^\s]+) \((.+):(.+):(.+)\)/; export function stackToComponentSources( stack: string, ): Array<[string, ?Stack]> { - const out = []; + const out: Array<[string, ?Stack]> = []; stack .split(STACK_DELIMETER) .slice(1) diff --git a/packages/react-devtools-shared/src/devtools/views/Components/types.js b/packages/react-devtools-shared/src/devtools/views/Components/types.js index 7e636e65dc52e..2eb4fc232cef2 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/types.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/types.js @@ -125,14 +125,16 @@ export type InspectedElement = { // TODO: Add profiling type +type Data = + | string + | Dehydrated + | Unserializable + | Array + | Array + | {[string]: Data}; + export type DehydratedData = { cleaned: Array>, - data: - | string - | Dehydrated - | Unserializable - | Array - | Array - | {[key: string]: string | Dehydrated | Unserializable, ...}, + data: Data, unserializable: Array>, }; diff --git a/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js b/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js index 5d2e6e9cf5bb1..100815a5ad566 100644 --- a/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js +++ b/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js @@ -150,6 +150,7 @@ function updateTree( // Clone nodes before mutating them so edits don't affect them. const getClonedNode = (id: number): CommitTreeNode => { + // $FlowFixMe[prop-missing] - recommended fix is to use object spread operator const clonedNode = ((Object.assign( {}, nodes.get(id), diff --git a/packages/react-devtools-shared/src/devtools/views/utils.js b/packages/react-devtools-shared/src/devtools/views/utils.js index 9f7aeccea32d4..d75c21bf802b7 100644 --- a/packages/react-devtools-shared/src/devtools/views/utils.js +++ b/packages/react-devtools-shared/src/devtools/views/utils.js @@ -134,7 +134,7 @@ export function serializeDataForCopy(props: Object): string { export function serializeHooksForCopy(hooks: HooksTree | null): string { // $FlowFixMe "HooksTree is not an object" - const cloned = Object.assign([], hooks); + const cloned = Object.assign(([]: Array), hooks); const queue = [...cloned]; diff --git a/packages/react-devtools-shared/src/hook.js b/packages/react-devtools-shared/src/hook.js index acecd13f06a69..cd135fa27fb34 100644 --- a/packages/react-devtools-shared/src/hook.js +++ b/packages/react-devtools-shared/src/hook.js @@ -29,7 +29,7 @@ export function installHook(target: any): DevToolsHook | null { } let targetConsole: Object = console; - let targetConsoleMethods = {}; + let targetConsoleMethods: {[string]: $FlowFixMe} = {}; for (const method in console) { targetConsoleMethods[method] = console[method]; } @@ -39,7 +39,7 @@ export function installHook(target: any): DevToolsHook | null { ): void { targetConsole = targetConsoleForTesting; - targetConsoleMethods = {}; + targetConsoleMethods = ({}: {[string]: $FlowFixMe}); for (const method in targetConsole) { targetConsoleMethods[method] = console[method]; } @@ -250,7 +250,7 @@ export function installHook(target: any): DevToolsHook | null { return; } - const originalConsoleMethods = {}; + const originalConsoleMethods: {[string]: $FlowFixMe} = {}; unpatchFn = () => { for (const method in originalConsoleMethods) { @@ -516,9 +516,9 @@ export function installHook(target: any): DevToolsHook | null { } // TODO: More meaningful names for "rendererInterfaces" and "renderers". - const fiberRoots = {}; + const fiberRoots: {[RendererID]: Set} = {}; const rendererInterfaces = new Map(); - const listeners = {}; + const listeners: {[string]: Array} = {}; const renderers = new Map(); const hook: DevToolsHook = { diff --git a/packages/react-devtools-shared/src/hooks/astUtils.js b/packages/react-devtools-shared/src/hooks/astUtils.js index 24cd0e5ea4611..137e40b452730 100644 --- a/packages/react-devtools-shared/src/hooks/astUtils.js +++ b/packages/react-devtools-shared/src/hooks/astUtils.js @@ -362,7 +362,7 @@ function getPotentialHookDeclarationsFromAST(sourceAST: File): NodePath[] { export function getHookNamesMappingFromAST( sourceAST: File, ): $ReadOnlyArray<{name: string, start: Position}> { - const hookStack = []; + const hookStack: Array<{name: string, start: $FlowFixMe}> = []; const hookNames = []; const pushFrame = (name: string, node: Node) => { const nameInfo = {name, start: {...node.loc.start}}; diff --git a/packages/react-devtools-shared/src/hooks/generateHookMap.js b/packages/react-devtools-shared/src/hooks/generateHookMap.js index 8d88ecc4c682e..be81581c92745 100644 --- a/packages/react-devtools-shared/src/hooks/generateHookMap.js +++ b/packages/react-devtools-shared/src/hooks/generateHookMap.js @@ -63,7 +63,7 @@ export function generateHookMap(sourceAST: File): HookMap { const hookNamesMapping = getHookNamesMappingFromAST(sourceAST); const namesMap: Map = new Map(); const names = []; - const mappings = []; + const mappings: Array = []; let currentLine = null; hookNamesMapping.forEach(({name, start}) => { diff --git a/packages/react-devtools-shared/src/hydration.js b/packages/react-devtools-shared/src/hydration.js index 1d046de69ca2f..e3dafa47b5d9c 100644 --- a/packages/react-devtools-shared/src/hydration.js +++ b/packages/react-devtools-shared/src/hydration.js @@ -16,7 +16,7 @@ import { setInObject, } from './utils'; -import type {DehydratedData} from 'react-devtools-shared/src/devtools/views/Components/types'; +import type {DehydratedData} from './devtools/views/Components/types'; export const meta = { inspectable: (Symbol('inspectable'): symbol), @@ -124,13 +124,7 @@ export function dehydrate( path: Array, isPathAllowed: (path: Array) => boolean, level?: number = 0, -): - | string - | Dehydrated - | Unserializable - | Array - | Array - | {[key: string]: string | Dehydrated | Unserializable, ...} { +): $PropertyType { const type = getDataType(data); let isPathAllowedCheck; @@ -304,7 +298,9 @@ export function dehydrate( if (level >= LEVEL_THRESHOLD && !isPathAllowedCheck) { return createDehydrated(type, true, data, cleaned, path); } else { - const object = {}; + const object: { + [string]: $PropertyType, + } = {}; getAllEnumerableKeys(data).forEach(key => { const name = key.toString(); object[name] = dehydrate( diff --git a/packages/react-devtools-shell/src/app/InspectableElements/CircularReferences.js b/packages/react-devtools-shell/src/app/InspectableElements/CircularReferences.js index c1bc9dcf1e45d..f75b31005610c 100644 --- a/packages/react-devtools-shell/src/app/InspectableElements/CircularReferences.js +++ b/packages/react-devtools-shell/src/app/InspectableElements/CircularReferences.js @@ -14,8 +14,15 @@ const arrayTwo = []; arrayTwo.push(arrayOne); arrayOne.push(arrayTwo); -const objectOne = {}; -const objectTwo = {objectOne}; +type ObjectOne = { + objectTwo?: ObjectTwo, +}; +type ObjectTwo = { + objectOne: ObjectOne, +}; + +const objectOne: ObjectOne = {}; +const objectTwo: ObjectTwo = {objectOne}; objectOne.objectTwo = objectTwo; export default function CircularReferences(): React.Node { diff --git a/packages/react-devtools-shell/src/app/index.js b/packages/react-devtools-shell/src/app/index.js index 6568fa7d3f019..f77d6c65d44a8 100644 --- a/packages/react-devtools-shell/src/app/index.js +++ b/packages/react-devtools-shell/src/app/index.js @@ -33,7 +33,7 @@ ignoreErrors([ ignoreWarnings(['Warning: componentWillReceiveProps has been renamed']); ignoreLogs([]); -const unmountFunctions = []; +const unmountFunctions: Array<() => void | boolean> = []; function createContainer() { const container = document.createElement('div'); diff --git a/packages/react-devtools-timeline/src/TimelineSearchContext.js b/packages/react-devtools-timeline/src/TimelineSearchContext.js index 830f98f1c35f7..604dbf180607a 100644 --- a/packages/react-devtools-timeline/src/TimelineSearchContext.js +++ b/packages/react-devtools-timeline/src/TimelineSearchContext.js @@ -40,7 +40,7 @@ type Action = type Dispatch = (action: Action) => void; -const EMPTY_ARRAY = []; +const EMPTY_ARRAY: Array = []; function reducer(state: State, action: Action): State { let {searchIndex, searchRegExp, searchResults, searchText} = state; diff --git a/packages/react-dom-bindings/src/client/ReactDOMComponent.js b/packages/react-dom-bindings/src/client/ReactDOMComponent.js index 13a41337f4c71..47047c98cecea 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMComponent.js +++ b/packages/react-dom-bindings/src/client/ReactDOMComponent.js @@ -672,7 +672,7 @@ export function diffProperties( for (styleName in lastStyle) { if (lastStyle.hasOwnProperty(styleName)) { if (!styleUpdates) { - styleUpdates = {}; + styleUpdates = ({}: {[string]: $FlowFixMe}); } styleUpdates[styleName] = ''; } @@ -725,7 +725,7 @@ export function diffProperties( (!nextProp || !nextProp.hasOwnProperty(styleName)) ) { if (!styleUpdates) { - styleUpdates = {}; + styleUpdates = ({}: {[string]: string}); } styleUpdates[styleName] = ''; } @@ -737,7 +737,7 @@ export function diffProperties( lastProp[styleName] !== nextProp[styleName] ) { if (!styleUpdates) { - styleUpdates = {}; + styleUpdates = ({}: {[string]: $FlowFixMe}); } styleUpdates[styleName] = nextProp[styleName]; } diff --git a/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js b/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js index 14699940e31fd..cfb770711fb93 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js +++ b/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js @@ -792,6 +792,7 @@ export function getResource( function preloadPropsFromRawProps( rawBorrowedProps: PreloadQualifyingProps, ): PreloadProps { + // $FlowFixMe[prop-missing] - recommended fix is to use object spread operator return Object.assign({}, rawBorrowedProps); } @@ -805,6 +806,7 @@ function titlePropsFromRawProps( } function stylePropsFromRawProps(rawProps: StyleQualifyingProps): StyleProps { + // $FlowFixMe[prop-missing] - recommended fix is to use object spread operator const props: StyleProps = Object.assign({}, rawProps); props['data-precedence'] = rawProps.precedence; props.precedence = null; @@ -813,6 +815,7 @@ function stylePropsFromRawProps(rawProps: StyleQualifyingProps): StyleProps { } function scriptPropsFromRawProps(rawProps: ScriptQualifyingProps): ScriptProps { + // $FlowFixMe[prop-missing] - recommended fix is to use object spread operator const props: ScriptProps = Object.assign({}, rawProps); return props; } @@ -1318,7 +1321,9 @@ function acquireScriptResource(resource: ScriptResource): Instance { } function attachLoadListeners(instance: Instance, resource: StyleResource) { - const listeners = {}; + const listeners: { + [string]: () => mixed, + } = {}; listeners.load = onResourceLoad.bind( null, instance, diff --git a/packages/react-dom-bindings/src/client/ReactDOMSelect.js b/packages/react-dom-bindings/src/client/ReactDOMSelect.js index 3ecc9974c637d..ebf94c7b79fa3 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMSelect.js +++ b/packages/react-dom-bindings/src/client/ReactDOMSelect.js @@ -77,7 +77,7 @@ function updateOptions( if (multiple) { const selectedValues = (propValue: Array); - const selectedValue = {}; + const selectedValue: {[string]: boolean} = {}; for (let i = 0; i < selectedValues.length; i++) { // Prefix to avoid chaos with special keys. selectedValue['$' + selectedValues[i]] = true; diff --git a/packages/react-dom-bindings/src/client/validateDOMNesting.js b/packages/react-dom-bindings/src/client/validateDOMNesting.js index f3d016f46e476..c8960f817d57f 100644 --- a/packages/react-dom-bindings/src/client/validateDOMNesting.js +++ b/packages/react-dom-bindings/src/client/validateDOMNesting.js @@ -434,7 +434,7 @@ if (__DEV__) { return null; }; - const didWarn = {}; + const didWarn: {[string]: boolean} = {}; validateDOMNesting = function( childTag: ?string, diff --git a/packages/react-dom-bindings/src/events/checkPassiveEvents.js b/packages/react-dom-bindings/src/events/checkPassiveEvents.js index 57267c47befaf..a0410117e7c8c 100644 --- a/packages/react-dom-bindings/src/events/checkPassiveEvents.js +++ b/packages/react-dom-bindings/src/events/checkPassiveEvents.js @@ -15,7 +15,9 @@ export let passiveBrowserEventsSupported: boolean = false; // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support if (canUseDOM) { try { - const options = {}; + const options: { + passive?: void, + } = {}; Object.defineProperty(options, 'passive', { get: function() { passiveBrowserEventsSupported = true; diff --git a/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js b/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js index 843c4bee1ff6d..921424e852e3f 100644 --- a/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js +++ b/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js @@ -191,7 +191,7 @@ export function createResponseState( : stringToPrecomputedChunk( '