Destructuring and assigning to an instance property

I have the following:

const {title} = {title: "Menu"};

alert( title ); // Menu

Now, if I have the following:

interface IEntry {title: string}
class Entry { title = 'Xoom' }

entry:IEntry = new Entry()

Why doesn’t the following work, and what is the correct form?

const {title: this.entry.title} = {title: "Menu"}

I was expecting the title property value to be assigned to this.entry.title.


You can’t use a const declaration if you don’t want to declare a new variable but destructure onto an existing object. The correct syntax would be

({title: this.entry.title} = {title: "Menu"});

See also Object destructuring without var, let or const.