TS2809
Declaration or statement expected. This '=' follows a block of statements, so if you intended to write a destructuring assignment, you might need to wrap the whole assignment in parentheses.
Broken Code ❌
function sum(a: number, b: number) {
console.log(a + b);
return {a, b};
}
{a, b} = sum(1000, 70);Fixed Code ✔️
This error occurs because the compiler interprets { a, b } as a block of statements rather than an object literal for destructuring. Add a const keyword so that the compiler recognizes it as an expression:
function sum(a: number, b: number) {
console.log(a + b);
return { a, b };
}
const { a, b } = sum(1000, 70);