简体   繁体   中英

Can JavaScript/TypeScript re-export all named exports under an alias without importing first?

Is there any way to do something like the following?

export * as MyAlias from 'path/to/somewhere';

I know it's possible to import everything first and then export it, but I would like to be as terse as possible and not need two lines for every re-export.

Specifically I am trying to group related modules together so consumers don't have to know anything about the underlying directory/file structure of the library.

I would suggest you usage of named exports. It can be used like this:

import * as ABC from 'path/to/somewhere';
export { ABC as MyAlias };

There is second option that will work as expected:

import * as ABC from 'path/to/somewhere';
const MyAlias = ABC;

export default MyAlias;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM