Infer type guard => array.filter(x => !!x) should refine Array<T|null> to Array · Issue #16069 · microsoft/TypeScript (original) (raw)
TypeScript Version: 2.3
Code
const evenSquares: number[] = [1, 2, 3, 4] .map(x => x % 2 === 0 ? x * x : null) .filter(x => !!x);
with strictNullChecks
enabled.
Expected behavior:
This should type check. The type of evenSquares
should be number[]
.
Actual behavior:
The type of evenSquares
is deduced as (number|null)[]
, despite the null values being removed via the call to .filter
.