2

There is the import syntax:

import * as foo from 'bar';

I similarly tried:

export * as foo from 'bar';

but that threw the errors:

ERROR in src/app/@theme/components/aComp/aComp.loader.ts(1,10): error TS1005: 'from' expected.
src/app/@theme/components/aComp/aComp.loader.ts(1,13): error TS1005: ';' expected.
src/app/@theme/components/aComp/aComp.loader.ts(1,17): error TS1005: ';' expected.
src/app/@theme/components/aComp/aComp.loader.ts(1,22): error TS1005: ';' expected.

there is also the export syntax:

export { default as foo } from 'bar';

Is there a way to do this for * as opposed to default?


(FYI I'm trying to remove require from the statement):

export const foo = require('bar');

the error below is thrown when ng serve is run including the .ts above:

ERROR in src/app/@theme/components/aComp/aComp.loader.ts(6,20): error TS2304: Cannot find name 'require'.
Nae
  • 14,209
  • 7
  • 52
  • 79

1 Answers1

10

No, there is not, but there is a proposal to add this syntax to the language.

Currently, you will need to use

import * as foo from 'bar';
export { foo }; // verbose: { foo as foo }

which is actually even closer to export const foo = require('bar'); than export * as foo from 'bar';, as it does provide foo in the local module scope as well.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375