0

What's the right way to do something like this? My goal is to have my list of things I'm exporting not have to be duplicated. Right now I have to make two lists of exports, one for the export, and one for the default export.

const exports = {
    Something,
    SomethingElse
}

export exports

export default exports

My goal is to be able to import like this:

import everything from 'my_module'

or

import {Something} from 'my_module'
Joren
  • 9,623
  • 19
  • 63
  • 104

1 Answers1

2

export exports is not valid syntax, it looks similar to something that TypeScript did support but that is deprecated in favour of modern syntax. Do not use it.

export default exports; and import everything from 'my_module'; would work together, but it's not recommended to default-export objects since it doesn't work with named imports.

Instead, use named exports:

export {
    Something,
    SomethingElse
}

(or put the export right on the declarations of Something and SomethingElse), then you can choose to do either

import {Something} from 'my_module';

or

import * as everything from 'my_module';
Bergi
  • 630,263
  • 148
  • 957
  • 1,375