0

I have a file that default exports an object containing constants. I'd also like to export each of the properties of the object. Is there a way to do this that doesn't involve writing them all out?

import keyMirror from 'keymirror';

// keymirror outputs an object with key = val.  eg. {a: a, b: b, ...}
const types = keyMirror({
  FREEFORM: null,
  GRAPH_IMAGE: null,
  ...
});

export default types;

export const FREEFORM = types.FREEFORM;
export const GRAPH_IMAGE = types.GRAPH_IMAGE;
...
CodeOcelot
  • 3,403
  • 3
  • 22
  • 23
  • 2
    ES6 exports need to be able to know the names of exports before the file has been executed, so they will need to be enumerated explicitly somewhere. – loganfsmyth Feb 24 '17 at 21:24

1 Answers1

1

Not sure about export, though you can use a single destructuring assignment

const {FREEFORM, GRAPH_IMAGE, ..} = types;
guest271314
  • 1
  • 15
  • 104
  • 177