我有一个默认情况下导出包含常量的对象的文件。我还想导出对象的每个属性。有没有一种方法可以解决这些问题,而无需全部写出来?

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;
...

最佳答案

尽管可以使用单个解构分配,但不确定export

const {FREEFORM, GRAPH_IMAGE, ..} = types;

10-08 13:42