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
usesexport =
and cannot be used withexport *
.
How to re-export from a module that uses export=
syntax? I have no control over the module with export=
syntax.
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.
The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.
Default Exports: Default exports are useful to export only a single object, function, variable. During the import, we can use any name to import.
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.
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 };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With