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
letarr: Array<Array<boolean>|number>=[[true]];for(leti=0;i<arr.length;i++)if(arr[i]instanceofArray&&arr[i].length>0)// Property 'length' does not exist on type 'number | boolean[]'.console.log(arr[i].length);// Property 'length' does not exist on type 'number | boolean[]'.if(arr[0]instanceofArray&&arr[0].length>0)console.log(true);
π Actual behavior
When attempting to compile, the condition arr[i] instanceof Array infers that arr[i] is an Array and has the property length but this inference is not continued throughout the rest of the condition nor body within the condition due to the variable i. This behavior does not match the behavior with a fixed-index as is shown in the fixed-index block.
π Expected behavior
Ideally, the inference from arr[i] instanceof Array would be continued into arr[i].length > 0 due to it being an && which makes the second condition never run unless arr[i] is an instance of Array. This should also be the case for the body of the if statement. This behavior is shown with a fixed index but does not apply to a variable one.
The text was updated successfully, but these errors were encountered:
Bug Report
π Search Terms
Looping, Condition, Inference, Chain, And, &&, Array
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
When attempting to compile, the condition
arr[i] instanceof Array
infers thatarr[i]
is anArray
and has the propertylength
but this inference is not continued throughout the rest of the condition nor body within the condition due to the variablei
. This behavior does not match the behavior with a fixed-index as is shown in the fixed-index block.π Expected behavior
Ideally, the inference from
arr[i] instanceof Array
would be continued intoarr[i].length > 0
due to it being an&&
which makes the second condition never run unlessarr[i]
is an instance ofArray
. This should also be the case for the body of the if statement. This behavior is shown with a fixed index but does not apply to a variable one.The text was updated successfully, but these errors were encountered: