iwpnd logo

Typescript destructuring re-assignment

Completely unnecessary, but if you ever want to re-assign a variable from within destructuring, here you go:

Destructuring needs to be either after a let, const or var declaration OR it needs to be in an expression context to distinguish it from a block statement.

let variable: number

if (true) {
	({ bla: variable } = someFunction());
} else {
	({ bla: variable } = someOtherFunction());
· til, typescript