Closed
Description
TypeScript Version: nightly (2.1.0-dev.20160919)
Code
function f(_: string) {}
const foo: {bar: null | string} = {bar: "foo"};
if (foo.bar) {
foo.bar.length; // works fine
(function () {
// works fine
foo.bar.length;
f(foo.bar);
})();
// both fail non-null assertion
[].map(_ => {
foo.bar.length;
f(foo.bar);
});
}
Expected behavior:
There should be no compile errors, as foo.bar
is guaranteed to be non-null inside the whole block
Actual behavior:
Inside the map callback, TS thinks that foo.bar
can be null. Strangely enough, an IIFE works just fine.