Microsoft/TypeScript
Auf GitHub ansehenNoncrashing property access through non-null assertion operator should narrow that property to NonNullable
Open
#15.655 geöffnet am 8. Mai 2017
BugDomain: check: Control FlowHelp Wanted
Repository-Metriken
- Stars
- (48.455 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)
Beschreibung
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
