diff --git a/packages/react-devtools-shared/src/Logger.js b/packages/react-devtools-shared/src/Logger.js index 0998f860a99c4..f5736ff4d00ff 100644 --- a/packages/react-devtools-shared/src/Logger.js +++ b/packages/react-devtools-shared/src/Logger.js @@ -74,7 +74,7 @@ export const logEvent: LogFunction = } : function logEvent() {}; -export const registerEventLogger = +export const registerEventLogger: (logFunction: LogFunction) => () => void = enableLogger === true ? function registerEventLogger(logFunction: LogFunction): () => void { if (enableLogger) { diff --git a/packages/react-devtools-shared/src/backend/agent.js b/packages/react-devtools-shared/src/backend/agent.js index 0d0fb5e81d7f8..13394da2aea85 100644 --- a/packages/react-devtools-shared/src/backend/agent.js +++ b/packages/react-devtools-shared/src/backend/agent.js @@ -254,7 +254,9 @@ export default class Agent extends EventEmitter<{ return this._rendererInterfaces; } - clearErrorsAndWarnings = ({rendererID}: {rendererID: RendererID}) => { + clearErrorsAndWarnings: ({rendererID: RendererID}) => void = ({ + rendererID, + }) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}"`); @@ -263,7 +265,7 @@ export default class Agent extends EventEmitter<{ } }; - clearErrorsForFiberID = ({id, rendererID}: ElementAndRendererID) => { + clearErrorsForFiberID: ElementAndRendererID => void = ({id, rendererID}) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}"`); @@ -272,7 +274,10 @@ export default class Agent extends EventEmitter<{ } }; - clearWarningsForFiberID = ({id, rendererID}: ElementAndRendererID) => { + clearWarningsForFiberID: ElementAndRendererID => void = ({ + id, + rendererID, + }) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}"`); @@ -281,7 +286,11 @@ export default class Agent extends EventEmitter<{ } }; - copyElementPath = ({id, path, rendererID}: CopyElementParams) => { + copyElementPath: CopyElementParams => void = ({ + id, + path, + rendererID, + }: CopyElementParams) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -290,7 +299,13 @@ export default class Agent extends EventEmitter<{ } }; - deletePath = ({hookID, id, path, rendererID, type}: DeletePathParams) => { + deletePath: DeletePathParams => void = ({ + hookID, + id, + path, + rendererID, + type, + }: DeletePathParams) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -344,18 +359,18 @@ export default class Agent extends EventEmitter<{ return null; } - getBackendVersion = () => { + getBackendVersion: () => void = () => { const version = process.env.DEVTOOLS_VERSION; if (version) { this._bridge.send('backendVersion', version); } }; - getBridgeProtocol = () => { + getBridgeProtocol: () => void = () => { this._bridge.send('bridgeProtocol', currentBridgeProtocol); }; - getProfilingData = ({rendererID}: {rendererID: RendererID}) => { + getProfilingData: ({rendererID: RendererID}) => void = ({rendererID}) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}"`); @@ -364,11 +379,11 @@ export default class Agent extends EventEmitter<{ this._bridge.send('profilingData', renderer.getProfilingData()); }; - getProfilingStatus = () => { + getProfilingStatus: () => void = () => { this._bridge.send('profilingStatus', this._isProfiling); }; - getOwnersList = ({id, rendererID}: ElementAndRendererID) => { + getOwnersList: ElementAndRendererID => void = ({id, rendererID}) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -378,13 +393,13 @@ export default class Agent extends EventEmitter<{ } }; - inspectElement = ({ + inspectElement: InspectElementParams => void = ({ forceFullData, id, path, rendererID, requestID, - }: InspectElementParams) => { + }) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -414,7 +429,7 @@ export default class Agent extends EventEmitter<{ } }; - logElementToConsole = ({id, rendererID}: ElementAndRendererID) => { + logElementToConsole: ElementAndRendererID => void = ({id, rendererID}) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -423,7 +438,11 @@ export default class Agent extends EventEmitter<{ } }; - overrideError = ({id, rendererID, forceError}: OverrideErrorParams) => { + overrideError: OverrideErrorParams => void = ({ + id, + rendererID, + forceError, + }) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -432,11 +451,11 @@ export default class Agent extends EventEmitter<{ } }; - overrideSuspense = ({ + overrideSuspense: OverrideSuspenseParams => void = ({ id, rendererID, forceFallback, - }: OverrideSuspenseParams) => { + }) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -445,14 +464,14 @@ export default class Agent extends EventEmitter<{ } }; - overrideValueAtPath = ({ + overrideValueAtPath: OverrideValueAtPathParams => void = ({ hookID, id, path, rendererID, type, value, - }: OverrideValueAtPathParams) => { + }) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -463,13 +482,13 @@ export default class Agent extends EventEmitter<{ // Temporarily support older standalone front-ends by forwarding the older message types // to the new "overrideValueAtPath" command the backend is now listening to. - overrideContext = ({ + overrideContext: SetInParams => void = ({ id, path, rendererID, wasForwarded, value, - }: SetInParams) => { + }) => { // Don't forward a message that's already been forwarded by the front-end Bridge. // We only need to process the override command once! if (!wasForwarded) { @@ -485,14 +504,14 @@ export default class Agent extends EventEmitter<{ // Temporarily support older standalone front-ends by forwarding the older message types // to the new "overrideValueAtPath" command the backend is now listening to. - overrideHookState = ({ + overrideHookState: OverrideHookParams => void = ({ id, hookID, path, rendererID, wasForwarded, value, - }: OverrideHookParams) => { + }) => { // Don't forward a message that's already been forwarded by the front-end Bridge. // We only need to process the override command once! if (!wasForwarded) { @@ -508,13 +527,13 @@ export default class Agent extends EventEmitter<{ // Temporarily support older standalone front-ends by forwarding the older message types // to the new "overrideValueAtPath" command the backend is now listening to. - overrideProps = ({ + overrideProps: SetInParams => void = ({ id, path, rendererID, wasForwarded, value, - }: SetInParams) => { + }) => { // Don't forward a message that's already been forwarded by the front-end Bridge. // We only need to process the override command once! if (!wasForwarded) { @@ -530,13 +549,13 @@ export default class Agent extends EventEmitter<{ // Temporarily support older standalone front-ends by forwarding the older message types // to the new "overrideValueAtPath" command the backend is now listening to. - overrideState = ({ + overrideState: SetInParams => void = ({ id, path, rendererID, wasForwarded, value, - }: SetInParams) => { + }) => { // Don't forward a message that's already been forwarded by the front-end Bridge. // We only need to process the override command once! if (!wasForwarded) { @@ -550,7 +569,9 @@ export default class Agent extends EventEmitter<{ } }; - reloadAndProfile = (recordChangeDescriptions: boolean) => { + reloadAndProfile: ( + recordChangeDescriptions: boolean, + ) => void = recordChangeDescriptions => { sessionStorageSetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY, 'true'); sessionStorageSetItem( SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY, @@ -563,14 +584,14 @@ export default class Agent extends EventEmitter<{ this._bridge.send('reloadAppForProfiling'); }; - renamePath = ({ + renamePath: RenamePathParams => void = ({ hookID, id, newPath, oldPath, rendererID, type, - }: RenamePathParams) => { + }) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -607,7 +628,9 @@ export default class Agent extends EventEmitter<{ } } - setTraceUpdatesEnabled = (traceUpdatesEnabled: boolean) => { + setTraceUpdatesEnabled: ( + traceUpdatesEnabled: boolean, + ) => void = traceUpdatesEnabled => { this._traceUpdatesEnabled = traceUpdatesEnabled; setTraceUpdatesEnabled(traceUpdatesEnabled); @@ -620,7 +643,7 @@ export default class Agent extends EventEmitter<{ } }; - syncSelectionFromNativeElementsPanel = () => { + syncSelectionFromNativeElementsPanel: () => void = () => { const target = window.__REACT_DEVTOOLS_GLOBAL_HOOK__.$0; if (target == null) { return; @@ -628,12 +651,14 @@ export default class Agent extends EventEmitter<{ this.selectNode(target); }; - shutdown = () => { + shutdown: () => void = () => { // Clean up the overlay if visible, and associated events. this.emit('shutdown'); }; - startProfiling = (recordChangeDescriptions: boolean) => { + startProfiling: ( + recordChangeDescriptions: boolean, + ) => void = recordChangeDescriptions => { this._recordChangeDescriptions = recordChangeDescriptions; this._isProfiling = true; for (const rendererID in this._rendererInterfaces) { @@ -645,7 +670,7 @@ export default class Agent extends EventEmitter<{ this._bridge.send('profilingStatus', this._isProfiling); }; - stopProfiling = () => { + stopProfiling: () => void = () => { this._isProfiling = false; this._recordChangeDescriptions = false; for (const rendererID in this._rendererInterfaces) { @@ -657,11 +682,16 @@ export default class Agent extends EventEmitter<{ this._bridge.send('profilingStatus', this._isProfiling); }; - stopInspectingNative = (selected: boolean) => { + stopInspectingNative: (selected: boolean) => void = selected => { this._bridge.send('stopInspectingNative', selected); }; - storeAsGlobal = ({count, id, path, rendererID}: StoreAsGlobalParams) => { + storeAsGlobal: StoreAsGlobalParams => void = ({ + count, + id, + path, + rendererID, + }) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -670,18 +700,18 @@ export default class Agent extends EventEmitter<{ } }; - updateConsolePatchSettings = ({ + updateConsolePatchSettings: ({ + appendComponentStack: boolean, + breakOnConsoleErrors: boolean, + browserTheme: BrowserTheme, + hideConsoleLogsInStrictMode: boolean, + showInlineWarningsAndErrors: boolean, + }) => void = ({ appendComponentStack, breakOnConsoleErrors, showInlineWarningsAndErrors, hideConsoleLogsInStrictMode, browserTheme, - }: { - appendComponentStack: boolean, - breakOnConsoleErrors: boolean, - showInlineWarningsAndErrors: boolean, - hideConsoleLogsInStrictMode: boolean, - browserTheme: BrowserTheme, }) => { // If the frontend preference has change, // or in the case of React Native- if the backend is just finding out the preference- @@ -696,7 +726,9 @@ export default class Agent extends EventEmitter<{ }); }; - updateComponentFilters = (componentFilters: Array) => { + updateComponentFilters: ( + componentFilters: Array, + ) => void = componentFilters => { for (const rendererID in this._rendererInterfaces) { const renderer = ((this._rendererInterfaces[ (rendererID: any) @@ -705,7 +737,7 @@ export default class Agent extends EventEmitter<{ } }; - viewAttributeSource = ({id, path, rendererID}: CopyElementParams) => { + viewAttributeSource: CopyElementParams => void = ({id, path, rendererID}) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -714,7 +746,7 @@ export default class Agent extends EventEmitter<{ } }; - viewElementSource = ({id, rendererID}: ElementAndRendererID) => { + viewElementSource: ElementAndRendererID => void = ({id, rendererID}) => { const renderer = this._rendererInterfaces[rendererID]; if (renderer == null) { console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`); @@ -723,11 +755,11 @@ export default class Agent extends EventEmitter<{ } }; - onTraceUpdates = (nodes: Set) => { + onTraceUpdates: (nodes: Set) => void = nodes => { this.emit('traceUpdates', nodes); }; - onFastRefreshScheduled = () => { + onFastRefreshScheduled: () => void = () => { if (__DEBUG__) { debug('onFastRefreshScheduled'); } @@ -735,7 +767,7 @@ export default class Agent extends EventEmitter<{ this._bridge.send('fastRefreshScheduled'); }; - onHookOperations = (operations: Array) => { + onHookOperations: (operations: Array) => void = operations => { if (__DEBUG__) { debug( 'onHookOperations', @@ -800,19 +832,22 @@ export default class Agent extends EventEmitter<{ this._bridge.send('unsupportedRendererVersion', rendererID); } - _throttledPersistSelection = throttle((rendererID: number, id: number) => { - // This is throttled, so both renderer and selected ID - // might not be available by the time we read them. - // This is why we need the defensive checks here. - const renderer = this._rendererInterfaces[rendererID]; - const path = renderer != null ? renderer.getPathForElement(id) : null; - if (path !== null) { - sessionStorageSetItem( - SESSION_STORAGE_LAST_SELECTION_KEY, - JSON.stringify(({rendererID, path}: PersistedSelection)), - ); - } else { - sessionStorageRemoveItem(SESSION_STORAGE_LAST_SELECTION_KEY); - } - }, 1000); + _throttledPersistSelection: any = throttle( + (rendererID: number, id: number) => { + // This is throttled, so both renderer and selected ID + // might not be available by the time we read them. + // This is why we need the defensive checks here. + const renderer = this._rendererInterfaces[rendererID]; + const path = renderer != null ? renderer.getPathForElement(id) : null; + if (path !== null) { + sessionStorageSetItem( + SESSION_STORAGE_LAST_SELECTION_KEY, + JSON.stringify(({rendererID, path}: PersistedSelection)), + ); + } else { + sessionStorageRemoveItem(SESSION_STORAGE_LAST_SELECTION_KEY); + } + }, + 1000, + ); } diff --git a/packages/react-devtools-shared/src/backend/utils.js b/packages/react-devtools-shared/src/backend/utils.js index 5c4b1289855b2..2b35ad0d5d26e 100644 --- a/packages/react-devtools-shared/src/backend/utils.js +++ b/packages/react-devtools-shared/src/backend/utils.js @@ -119,7 +119,9 @@ export function copyWithSet( return updated; } -export function getEffectDurations(root: Object) { +export function getEffectDurations( + root: Object, +): {effectDuration: any | null, passiveEffectDuration: any | null} { // Profiling durations are only available for certain builds. // If available, they'll be stored on the HostRoot. let effectDuration = null; diff --git a/packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenu.js b/packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenu.js index e29a33bb32610..e167b28df6b9e 100644 --- a/packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenu.js +++ b/packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenu.js @@ -53,7 +53,7 @@ type Props = { id: string, }; -export default function ContextMenu({children, id}: Props) { +export default function ContextMenu({children, id}: Props): React.Node { const {hideMenu, registerMenu} = useContext( RegistryContext, ); diff --git a/packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenuItem.js b/packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenuItem.js index df313307b15f8..29f49fe224381 100644 --- a/packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenuItem.js +++ b/packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenuItem.js @@ -21,7 +21,11 @@ type Props = { title: string, }; -export default function ContextMenuItem({children, onClick, title}: Props) { +export default function ContextMenuItem({ + children, + onClick, + title, +}: Props): React.Node { const {hideMenu} = useContext(RegistryContext); const handleClick = event => { diff --git a/packages/react-devtools-shared/src/devtools/ContextMenu/Contexts.js b/packages/react-devtools-shared/src/devtools/ContextMenu/Contexts.js index f8d310a02f72b..2e30fc5c294f6 100644 --- a/packages/react-devtools-shared/src/devtools/ContextMenu/Contexts.js +++ b/packages/react-devtools-shared/src/devtools/ContextMenu/Contexts.js @@ -7,6 +7,8 @@ * @flow */ +import type {ReactContext} from 'shared/ReactTypes'; + import {createContext} from 'react'; export type ShowFn = ({data: Object, pageX: number, pageY: number}) => void; @@ -81,8 +83,10 @@ export type RegistryContextType = { registerMenu: typeof registerMenu, }; -export const RegistryContext = createContext({ - hideMenu, - showMenu, - registerMenu, -}); +export const RegistryContext: ReactContext = createContext( + { + hideMenu, + showMenu, + registerMenu, + }, +); diff --git a/packages/react-devtools-shared/src/devtools/ProfilerStore.js b/packages/react-devtools-shared/src/devtools/ProfilerStore.js index b74e958cefa77..979b73c798914 100644 --- a/packages/react-devtools-shared/src/devtools/ProfilerStore.js +++ b/packages/react-devtools-shared/src/devtools/ProfilerStore.js @@ -201,10 +201,10 @@ export default class ProfilerStore extends EventEmitter<{ // We do this to avoid mismatches on e.g. CommitTreeBuilder that would cause errors. } - _takeProfilingSnapshotRecursive = ( + _takeProfilingSnapshotRecursive: ( elementID: number, profilingSnapshots: Map, - ) => { + ) => void = (elementID, profilingSnapshots) => { const element = this._store.getElementByID(elementID); if (element !== null) { const snapshotNode: SnapshotNode = { @@ -223,7 +223,7 @@ export default class ProfilerStore extends EventEmitter<{ } }; - onBridgeOperations = (operations: Array) => { + onBridgeOperations: (operations: Array) => void = operations => { // The first two values are always rendererID and rootID const rendererID = operations[0]; const rootID = operations[1]; @@ -249,7 +249,9 @@ export default class ProfilerStore extends EventEmitter<{ } }; - onBridgeProfilingData = (dataBackend: ProfilingDataBackend) => { + onBridgeProfilingData: ( + dataBackend: ProfilingDataBackend, + ) => void = dataBackend => { if (this._isProfiling) { // This should never happen, but if it does- ignore previous profiling data. return; @@ -279,14 +281,14 @@ export default class ProfilerStore extends EventEmitter<{ } }; - onBridgeShutdown = () => { + onBridgeShutdown: () => void = () => { this._bridge.removeListener('operations', this.onBridgeOperations); this._bridge.removeListener('profilingData', this.onBridgeProfilingData); this._bridge.removeListener('profilingStatus', this.onProfilingStatus); this._bridge.removeListener('shutdown', this.onBridgeShutdown); }; - onProfilingStatus = (isProfiling: boolean) => { + onProfilingStatus: (isProfiling: boolean) => void = isProfiling => { if (isProfiling) { this._dataBackends.splice(0); this._dataFrontend = null; diff --git a/packages/react-devtools-shared/src/devtools/ProfilingCache.js b/packages/react-devtools-shared/src/devtools/ProfilingCache.js index 6384db8d1c628..ba4d3043247d2 100644 --- a/packages/react-devtools-shared/src/devtools/ProfilingCache.js +++ b/packages/react-devtools-shared/src/devtools/ProfilingCache.js @@ -33,26 +33,20 @@ export default class ProfilingCache { this._profilerStore = profilerStore; } - getCommitTree = ({ - commitIndex, - rootID, - }: { + getCommitTree: ({ commitIndex: number, rootID: number, - }) => + }) => CommitTree = ({commitIndex, rootID}) => getCommitTree({ commitIndex, profilerStore: this._profilerStore, rootID, }); - getFiberCommits = ({ - fiberID, - rootID, - }: { + getFiberCommits: ({ fiberID: number, rootID: number, - }): Array => { + }) => Array = ({fiberID, rootID}) => { const cachedFiberCommits = this._fiberCommits.get(fiberID); if (cachedFiberCommits != null) { return cachedFiberCommits; @@ -71,15 +65,11 @@ export default class ProfilingCache { return fiberCommits; }; - getFlamegraphChartData = ({ - commitIndex, - commitTree, - rootID, - }: { + getFlamegraphChartData: ({ commitIndex: number, commitTree: CommitTree, rootID: number, - }): FlamegraphChartData => + }) => FlamegraphChartData = ({commitIndex, commitTree, rootID}) => getFlamegraphChartData({ commitIndex, commitTree, @@ -87,15 +77,11 @@ export default class ProfilingCache { rootID, }); - getRankedChartData = ({ - commitIndex, - commitTree, - rootID, - }: { + getRankedChartData: ({ commitIndex: number, commitTree: CommitTree, rootID: number, - }): RankedChartData => + }) => RankedChartData = ({commitIndex, commitTree, rootID}) => getRankedChartData({ commitIndex, commitTree, diff --git a/packages/react-devtools-shared/src/devtools/store.js b/packages/react-devtools-shared/src/devtools/store.js index b51597f43a528..11d4a9a5f1f39 100644 --- a/packages/react-devtools-shared/src/devtools/store.js +++ b/packages/react-devtools-shared/src/devtools/store.js @@ -828,10 +828,10 @@ export default class Store extends EventEmitter<{ } } - _adjustParentTreeWeight = ( + _adjustParentTreeWeight: ( parentElement: Element | null, weightDelta: number, - ) => { + ) => void = (parentElement, weightDelta) => { let isInsideCollapsedSubTree = false; while (parentElement != null) { @@ -869,20 +869,17 @@ export default class Store extends EventEmitter<{ } } - onBridgeNativeStyleEditorSupported = ({ - isSupported, - validAttributes, - }: { + onBridgeNativeStyleEditorSupported: ({ isSupported: boolean, validAttributes: ?$ReadOnlyArray, - }) => { + }) => void = ({isSupported, validAttributes}) => { this._isNativeStyleEditorSupported = isSupported; this._nativeStyleEditorValidAttributes = validAttributes || null; this.emit('supportsNativeStyleEditor'); }; - onBridgeOperations = (operations: Array) => { + onBridgeOperations: (operations: Array) => void = operations => { if (__DEBUG__) { console.groupCollapsed('onBridgeOperations'); debug('onBridgeOperations', operations.join(',')); @@ -1328,15 +1325,15 @@ export default class Store extends EventEmitter<{ // this message enables the backend to override the frontend's current ("saved") filters. // This action should also override the saved filters too, // else reloading the frontend without reloading the backend would leave things out of sync. - onBridgeOverrideComponentFilters = ( + onBridgeOverrideComponentFilters: ( componentFilters: Array, - ) => { + ) => void = componentFilters => { this._componentFilters = componentFilters; setSavedComponentFilters(componentFilters); }; - onBridgeShutdown = () => { + onBridgeShutdown: () => void = () => { if (__DEBUG__) { debug('onBridgeShutdown', 'unsubscribing from Bridge'); } @@ -1373,30 +1370,36 @@ export default class Store extends EventEmitter<{ } }; - onBackendStorageAPISupported = (isBackendStorageAPISupported: boolean) => { + onBackendStorageAPISupported: ( + isBackendStorageAPISupported: boolean, + ) => void = isBackendStorageAPISupported => { this._isBackendStorageAPISupported = isBackendStorageAPISupported; this.emit('supportsReloadAndProfile'); }; - onBridgeSynchronousXHRSupported = (isSynchronousXHRSupported: boolean) => { + onBridgeSynchronousXHRSupported: ( + isSynchronousXHRSupported: boolean, + ) => void = isSynchronousXHRSupported => { this._isSynchronousXHRSupported = isSynchronousXHRSupported; this.emit('supportsReloadAndProfile'); }; - onBridgeUnsupportedRendererVersion = () => { + onBridgeUnsupportedRendererVersion: () => void = () => { this._unsupportedRendererVersionDetected = true; this.emit('unsupportedRendererVersionDetected'); }; - onBridgeBackendVersion = (backendVersion: string) => { + onBridgeBackendVersion: (backendVersion: string) => void = backendVersion => { this._backendVersion = backendVersion; this.emit('backendVersion'); }; - onBridgeProtocol = (bridgeProtocol: BridgeProtocol) => { + onBridgeProtocol: ( + bridgeProtocol: BridgeProtocol, + ) => void = bridgeProtocol => { if (this._onBridgeProtocolTimeoutID !== null) { clearTimeout(this._onBridgeProtocolTimeoutID); this._onBridgeProtocolTimeoutID = null; @@ -1411,7 +1414,7 @@ export default class Store extends EventEmitter<{ } }; - onBridgeProtocolTimeout = () => { + onBridgeProtocolTimeout: () => void = () => { this._onBridgeProtocolTimeoutID = null; // If we timed out, that indicates the backend predates the bridge protocol, diff --git a/packages/react-devtools-shared/src/devtools/utils.js b/packages/react-devtools-shared/src/devtools/utils.js index 86c9dd6c8cefe..1a4719f6df8f4 100644 --- a/packages/react-devtools-shared/src/devtools/utils.js +++ b/packages/react-devtools-shared/src/devtools/utils.js @@ -149,7 +149,7 @@ export function printStore( // We use JSON.parse to parse string values // e.g. 'foo' is not valid JSON but it is a valid string // so this method replaces e.g. 'foo' with "foo" -export function sanitizeForParse(value: any) { +export function sanitizeForParse(value: any): any | string { if (typeof value === 'string') { if ( value.length >= 2 && @@ -162,7 +162,7 @@ export function sanitizeForParse(value: any) { return value; } -export function smartParse(value: any) { +export function smartParse(value: any): any | void | number { switch (value) { case 'Infinity': return Infinity; diff --git a/packages/react-devtools-shared/src/devtools/views/Button.js b/packages/react-devtools-shared/src/devtools/views/Button.js index bdd84b57da431..a629e8d7b75a4 100644 --- a/packages/react-devtools-shared/src/devtools/views/Button.js +++ b/packages/react-devtools-shared/src/devtools/views/Button.js @@ -26,7 +26,7 @@ export default function Button({ testName, title, ...rest -}: Props) { +}: Props): React.Node { let button = ( // $FlowFixMe unsafe spread