flow icon indicating copy to clipboard operation
flow copied to clipboard

Failed nullability check when non-nullability is guarantied by expression tree

Open nbotalov opened this issue 9 years ago • 1 comments

I'm extracting boolean predicate to prevent code duplication:

type Props = {
   ...
    tableSort: ?TableSort
}
...
const {tableSort} = this.props;
const theSameField = tableSort && columnDescription.dataField === tableSort.field;
const sortClasses = classNames({
     'data-table__sort_up': theSameField && tableSort.order == SortingOrder.ASC,
     'data-table__sort_down': theSameField && tableSort.order == SortingOrder.DESC
});

and getting error that tableSort may be null or undefined in both lines (tableSort.order). But theSameField cannot be true if tableSort is null or undefined. If inline

tableSort && columnDescription.dataField === tableSort.field

two times, no inspections

nbotalov avatar Jan 09 '17 14:01 nbotalov

Flow does not keep refinements in variables. You should explicitly check property before usage.

TrySound avatar Feb 09 '19 14:02 TrySound