flow
flow copied to clipboard
Failed nullability check when non-nullability is guarantied by expression tree
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
Flow does not keep refinements in variables. You should explicitly check property before usage.