Destructuring with `await`

accordingly to your logic this decompress to:

obj.then(result => {
  const a = result.a;
  const b = result.b;
  const c = result.c;
});

not sure why you wrote that instead ... my proposal though, is that:

const { a, await b, c } = obj;

decompress (if this is the right term) into:

const { a, c } = obj;
const [ b ] = await Promise.all([ obj.b ]);

Add any other await in destructuring and the logic is the same:

const { a, await b, c, d, await e } = obj;

// transpile into
const { a, c, d } = obj;
const [ b, e ] = await Promise.all([ obj.b, obj.c ]);

I hope the proposal is more clear now.

1 Like