Typescript Object destructuring results in "Property assignment expected."

Rick picture Rick · Jan 19, 2016 · Viewed 22k times · Source

I am transitioning a project from Babel to Typescript and receive the following compiler error:

error TS1136: Property assignment expected.

from code that looks like this:

var auth = {...this.props.auth};

This code previously worked fine under Babel, but causes the error above when attempting to compile via Typescript. Is object destructuring different in Typescript?

Answer

MinusFour picture MinusFour · Jan 19, 2016

The feature you are looking for is Object spread/rest operators (proposed for ES7). It looks like it's planned but not yet implemented:

We want to wait for the proposal to reach Stage 3 before addressing this.

More info here.

Edit: The proposal is in stage-3. We'll likely see it drafted on ES2018 (ES9). Support has been added to TypeScript as well (starting from 2.1).