Affected options:
0.42.0 on Mac OS X,
0.42.0 and master on https://flowtype.org/try/
Code example:
const shape: [number, number] | [number] | [] = [1,2];
if (shape.length === 2)
shape[1]
Expected behavior:
possible types gets limited to the ones that infers with .length === 2 rule, and act accordingly
Actual behavior:
4: shape[1] ^ access of computed property/element. Out of bound access. This tuple has 0 elements and you tried to access index 1 of
4: shape[1]
^ tuple type
4: shape[1] ^ access of computed property/element. Out of bound access. This tuple has 1 elements and you tried to access index 1 of
4: shape[1]
^ tuple type
Other notes:
I'm afraid I cannot use number[] as type, as long I'm working on multi-dimensional lib array and actual behavior is more like Matrix<[number, number]> to validate the matrix operations, e.g. vector can only be multiplied with vector, and 3d matrix - only with 3d matrix. Also this is nice approach to limit the amount of max dimensions (5d is max possible dimensions for my case)
I guess this should work, as long as tuples have exact length
@vkurchatkin Do you know if there is anyone looking after these issues?
Issue still there for why I come, Try Flow.
Most helpful comment
I guess this should work, as long as tuples have exact length