title: Typescript: Null check doesn't work inside array.map function
body: <p>Why my nullable type that was previously checked before the map function doesn't work inside the map? </p>
  
  <pre><code>function x() {
    let y: number | null;
    y = null;
  
    if (!y) {
      return [];
    }
  
    return [1, 2, 3, 4].map((z) =&gt; {
      // error: y cannot be null
      return z + y;
    })
  }
  </code></pre>
  
  <p><a href="http://www.typescriptlang.org/play/?ssl=12&amp;ssc=2&amp;pln=1&amp;pc=1#code/GYVwdgxgLglg9mABADwBQEpEG8BQjEA2AplIgJ4BciYIAtgEZEBOiAPtSAQQNx7mIBeDl158YwRKgCEZTLnz4mJEEyQBtALq98AXxx8lUFeoCMAGkQAmCwGYLAFg0A6WgEMADqlQAvTAIB82HyKyqqI3ogA1OTaiDroODpAA" rel="nofollow noreferrer">The code on TypeScript Playground</a>.</p>