-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
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.
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug