How do I loop over an array of tuples in TypeScript? e.g.
for (const [x, y] of [['a', 1], ['b', 2]]) {
y + 1;
}
complains:
error TS2365: Operator '+' cannot be applied to types 'string | number' and '1'.
If I understand correctly, TypeScript infers type (string | number)[][] for the loop expression, which is why the loop variable y has type string | number although actually it can only ever have type number?
I think https://github.com/microsoft/TypeScript/issues/3369 is the issue that keeps TypeScript from inferring the suitable type. What is the current solution for looping over an array of tuples? Type assertions?