Skip to content

Commit

Permalink
Fix flow errors due to missing type narrowing capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Dec 14, 2020
1 parent 1dafc3b commit e3e95fb
Showing 1 changed file with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit e3e95fb

Please sign in to comment.