From e3e95fbf56947aeda4c416ac93eec5c8b0bc4f38 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Tue, 15 Dec 2020 00:03:44 +0100 Subject: [PATCH] Fix flow errors due to missing type narrowing capabilities --- .../devtools/views/Components/TreeContext.js | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js b/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js index 31ebf164a9110..1a3a960783608 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js @@ -386,13 +386,22 @@ function reduceTreeState(store: Store, state: State, action: Action): State { } // TODO (inline errors) The element indices are incorrect if the element is hidden in a collapsed tree. // Shouldn't hidden elements excluded from computing a valid index? - const elementIndicesWithErrorsOrWarnings = Array.from( + const elementIndicesWithErrorsOrWarnings: number[] = Array.from( store.errorsAndWarnings.keys(), - elementId => store.getIndexOfElementID(elementId), - ); + ) + .map(elementId => { + // $FlowFixMe https://github.com/facebook/flow/issues/1414 + return store.getIndexOfElementID(elementId); + }) + .filter(elementIndex => { + return elementIndex !== null; + }); const predecessors = elementIndicesWithErrorsOrWarnings.filter( elementIndex => { - return elementIndex !== null && elementIndex < selectedElementIndex; + return ( + selectedElementIndex === null || + elementIndex < selectedElementIndex + ); }, ); if (predecessors.length === 0) { @@ -409,13 +418,22 @@ function reduceTreeState(store: Store, state: State, action: Action): State { return state; } - const elementIndicesWithErrorsOrWarnings = Array.from( + const elementIndicesWithErrorsOrWarnings: number[] = Array.from( store.errorsAndWarnings.keys(), - elementId => store.getIndexOfElementID(elementId), - ); + ) + .map(elementId => { + // $FlowFixMe https://github.com/facebook/flow/issues/1414 + return store.getIndexOfElementID(elementId); + }) + .filter(elementIndex => { + return elementIndex !== null; + }); const successors = elementIndicesWithErrorsOrWarnings.filter( elementIndex => { - return elementIndex !== null && elementIndex > selectedElementIndex; + return ( + selectedElementIndex === null || + elementIndex > selectedElementIndex + ); }, ); if (successors.length === 0) {