Microsoft/TypeScript
GitHub ã§èŠãNon-null assertion should work on possibly-uninitialized auto-typed `let` variables
Open
#52,439 opened on 2023幎1æ26æ¥
Experience EnhancementHelp WantedSuggestion
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
Bug Report
ð Search Terms
non-null postfix bang implicit any
ð Version & Regression Information
- This is the behavior in every version I tried
⯠Playground Link
ð» Code
let foo;
if (Math.random() > 0.5) {
foo = "hello";
}
// bar: string | undefined, seems fine
let bar = foo;
/* -- pretend I know foo is defined for other reasons -- */
// Error, foo is implicitly any
let baz = foo!;
ð Actual behavior
Implicit any on foo!
ð Expected behavior
Since the inferred type of foo (as seen in bar) is string | undefined, foo! should trivially have the type string