0

I'm really confused by the following statement in an index.ts:

import z from 'path/to/z';
export const { x: y } = z;

What does the second line actually export and how does the value of z correlate with it? Also, what purpose does this kind of export serve?

leonheess
  • 16,068
  • 14
  • 77
  • 112

1 Answers1

6

This is an export declaration with a const destructuring pattern. y is the variable being declared, which is initialised with the x property of z.

It could (and perhaps should) be written as the equivalent

export const y = z.x;
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • 4
    The code in the question definitely falls under the _"too fancy for its own good"_ banner – Phil Feb 09 '22 at 23:13