0

I have several modules exporting various types, classes etc. Is it possible to create another module that aggregates all the exports from those modules in a nice way? Specifically, is it possible to from one module export all exports of another module as a sub-module or namespace?

sub.ts:

export const foo = 42;
export const bar = 43;

index.ts:

import * as Sub from './sub.ts'
// Now Sub.foo and Sub.bar exists

export class Foo {
}

// export all members from sub as 'Sub'
export Sub;

my-client.ts:

import {Sub, Foo} from './index'

const x = Sub.foo;
const y = new Foo();

The export Sub line gives expression statement is not assignment or call.

How can something like this be done to form a logical entrypoint to a module consisting of several other modules' functionality?

JHH
  • 8,567
  • 8
  • 47
  • 91

1 Answers1

1

you can use:

// export all members from sub as 'Sub'
export {  
  Sub
};

for more info checkout https://stackoverflow.com/a/42731800/908464

R Pasha
  • 700
  • 5
  • 21