TS1091
Only a single variable declaration is allowed in a 'for...in' statement.
The for...in
loop can be used to loop over all enumerable keys in an object.
If you try to loop with multiple value variables this error will appear:
const list = [[1, 2], [3, 4]];
for (const a, b in list) {
// ...
}
const obj = { a: 1, b: 2 };
for (const a, b in obj) {
// ...
}
Fix: Use Object.entries to iterate over object keys and values.
To loop over the keys and values of an object, use
Object.entries
:
const obj = { a: 1, b: 2 };
for (const [key, val] of Object.entries(obj)) {
/// ...
}
Fix: Use destructuring.
For other iterables, use destructuring:
const list = [[1, 2], [3, 4]];
for (const [a, b] of list) {
// ...
}