Microsoft/TypeScript
Vedi su GitHubNoncrashing property access through non-null assertion operator should narrow that property to NonNullable
Open
#15.655 aperta il 8 mag 2017
BugDomain: check: Control FlowHelp Wanted
Metriche repository
- Star
- (48.455 star)
- Metriche merge PR
- (Merge medio 6g 17h) (9 PR mergiate in 30 g)
Descrizione
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
