Microsoft/TypeScript
Noncrashing property access through non-null assertion operator should narrow that property to NonNullable
Ouverte
#15 655 ouverte le 8 mai 2017
BugDomain: check: Control FlowHelp Wanted
Métriques du dépôt
- Stars
- (108 860 étoiles)
- Métriques de merge PR
- (Métriques PR en attente)
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
