checker.ts: explicit boolean type annotation overrides type guard, silencing an error #45594
Labels
Unactionable
There isn't something we can do with this issue
Working as Intended
The behavior described is the intended behavior; this is not a bug
Bug Report
I wouldn't call this a bug, but rather a piece of code inconsistent with "best practices" and prone to cause more confusion in future.
This is a spin-off from issue #45572. I have investigated the line mentioned in @andrewbranch 's comment, and answered my own question in the subsequent reply.
If you indeed recognize it as a bug, please read the "Solution" section and assign the bug to me. Thanks for working on and maintaining such a wonderful project!
🔎 Search Terms
Control flow analysis of aliased conditional expressions
Type guard result saved to variable
🕗 Version & Regression Information
This was introduced in v4.4.0-beta, by pull request #44730 "Control flow analysis of aliased conditional expressions", commit 08b6e2e.
"inlining CFA" through an explicit type annotation:
⏯ Playground Links & 💻 Code
Playground link illustrating the "Before" code example
Before #44730 (v4.3.5):
Playground link illustrating the "After, current" code example
After (with explicit type annotation, e.g. current version, WITHOUT error) #44730 (v4.4-beta):
Playground link illustrating the "After, current" code example
After #44730 (edited out the type annotation, GIVES ERROR) (v4.4-beta):
✅ Solution
Playground link the proposed solution based on prev. examples
The text was updated successfully, but these errors were encountered: