Microsoft/TypeScript
在 GitHub 查看Noncrashing property access through non-null assertion operator should narrow that property to NonNullable
Open
#15,655 创建于 2017年5月8日
BugDomain: check: Control FlowHelp Wanted
描述
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
