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
#5442 only has changes typeof type guards and composite type guards.
But this behavior is actually by spec - with instanceof type guards, we only affirmatively narrow (so in the true branch) - the logic being that since TS uses structural typing, even if instanceof catches something, instanceofnot catching something doesn't mean that the thing you're checking is not a given type. (In effect, val instanceof Array does not imply that val does not have the type of an array, since it could still have the shape of an array but not the same constructor.) User-defined type guards are more strict, as we assume when you make a type predicate that it's capable of being exhaustive, and typeof is more strict because primitives are effectively nominal.
see example in playground
val has one of two types strting[] or string
in 'if' condition checked instanceofArray
in else statement compiler should know that val has string type
The text was updated successfully, but these errors were encountered: