TS2491
The left-hand side of a 'for...in' statement cannot be a destructuring pattern.
Broken Code ❌
const obj = {
age: 36,
name: 'Benny',
};
for (const [key, value] in Object.entries(obj)) {
console.log(key, value);
}Solution:
Change the for...in loop to a for...of loop to correctly iterate over entries of an object using destructuring.
Fixed Code ✔️
const obj = {
age: 36,
name: 'Benny',
};
for (const [key, value] of Object.entries(obj)) {
console.log(key, value);
}