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
The following fails on referring to "splice" because after the instanceof evaluation, the "foo" object changes from type boolean[] to type never, which doesn't have splice defined:
However I'm not sure completely. This seems very buggy and unexpected because I do not expect foo to change typings after a comparison. Code that was previously compiling fine is no longer compiling.
In the foo instanceof Array check, the type checker narrows the type of foo to only the subset that are arrays. That turns out to be all possible values of foo, so foo has type boolean[] in the true branch. But in the false branch the type checker narrows to the subset that aren't arrays. That turns out to be nothing, so foo has type never in the false branch.
TypeScript Version: 2.0.2
Code
This works:
The following fails on referring to "splice" because after the instanceof evaluation, the "foo" object changes from type
boolean[]
to typenever
, which doesn't have splice defined:Strangely, if I change the condition to AND instead of OR, we don't have any issues:
Or, if I change the order of evaluation, that works as well:
Note, this isn't something specific to arrays. You can change the
boolean[]
toHTMLElement
, same sort of problem.Expected behavior:
No errors in this case.
Actual behavior:
Property 'splice' does not exist on type 'never'.
The text was updated successfully, but these errors were encountered: