Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reexport `*` from a module that uses `export =`

Tags:

typescript

I have a module m:

export = {
    a: 3
}

And then in my index.ts I want to re-export everything that m is exporting, so I use:

export * from './m';

But it gives me an error:

Error: TS2498:Module D:/Projects/typescript/m uses export = and cannot be used with export *.

How to re-export from a module that uses export= syntax? I have no control over the module with export= syntax.

like image 879
Max Koretskyi Avatar asked Jan 27 '17 11:01

Max Koretskyi


People also ask

Can you import module exports?

The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the import declaration or dynamic import.

What can be exported from a module?

The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.

Why would you create a default export in a module?

Default Exports: Default exports are useful to export only a single object, function, variable. During the import, we can use any name to import.

Can we export interface?

Use a named export to export an interface in TypeScript, e.g. export interface Person{} . The exported interface can be imported by using a named import as import {Person} from './another-file' . You can have as many named exports as necessary in a single file.


1 Answers

You can use

import m = require("./m");
export {m};

or

import m = require("./m");
export default m;

Old style imports export =, require() aren't compatible with module exports.

Refer to documentation

UPDATE for JSON file import The following works using the from syntax, once you turn on the required tsconfig option. Available since 2.9.

import myObjectName from './path/to/file.json';
export { myObjectName };
like image 97
mleko Avatar answered Sep 22 '22 17:09

mleko