Microsoft/TypeScript
View on GitHubNoncrashing property access through non-null assertion operator should narrow that property to NonNullable
Open
#15,655 opened on May 8, 2017
BugDomain: check: Control FlowHelp Wanted
Description
TypeScript Version: 2.3 (Playground)
Code
Using strictNullChecks.
interface Foo {
optional?: number;
}
interface Bar {
foo?: Foo;
}
function test(bar: Bar) {
if (bar.foo!.optional) {
let num: number = bar.foo.optional;
}
if (bar.foo && bar.foo.optional) {
let num: number = bar.foo.optional;
}
}
Expected behavior: No errors or warnings.
Actual behavior:
numin firstifblock isnumber | undefinedbar.fooin firstifblock can beundefined
