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
I believe this is by design, and applies to all type guards, not just those for discriminated unions. The problem is that the compiler cannot in general be sure when the nested function will be called, so it's not safe to assume the narrowed type will still apply by the time the function is actually called. The variable may have been re-assigned by then.
There are a couple of special cases involving IIFEs and consts where the narrowing can safely cross into the nested function body, and the compiler handles these cases correctly. See #8849.
TypeScript Version:
nightly (1.9.0-dev.20160619-1.0)
Code
Expected behavior: both
s
usages to narrow to typeRectangle
Actual behavior: the
s
in the nested function scope has typeRectangle | Circle
The text was updated successfully, but these errors were encountered: