You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the else clause above, the compiler has computed the control flow type of m to be never. But, because of #8548, the if statement is treated as an assertion that mcould be null, and the control flow type of m is therefore changed to null. And since the control flow type of a variable following an if statement is the union of the control flow types at the end of each of the branches, the type of m becomes string | null.
Now, while this explains what's happening, it doesn't necessarily make it right. Without the behavior in #8548, the type of m would be never in the else clause (since, according to control flow analysis, it could never execute). And since string | never is the same as string, we'd give type string to m after the if statement as expected. That certainly would make more sense here.
It may be that #8548 causes more harm than good. We've already had some feedback to that effect, so I'll think about alternatives. One issue is that #8458 also solves the problem we had with this code:
During control flow analysis, the initial type of x is number, which cases x to be given type never in the true branch of the conditional operator, which then causes x.slice() to be an error. If we were to back out #8548, we'd need a different solution to that issue.
An
if
with condition that contains an explicited short-circuit evaluation cause null check to fail:The text was updated successfully, but these errors were encountered: