Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export default const with Typescript

I have this in a TS file:

exports.default = module.exports;

(This is to support both Node style and TS style imports.)

Is there a way to create the above line of code with pure TS instead of JS?

I tried this:

export default const = module.exports;

and that does not transpile.

like image 638
Alexander Mills Avatar asked Oct 30 '22 06:10

Alexander Mills


1 Answers

Somewhat counterintuitively, the answer appears to be:

export default module.exports;

that's it.

however, in order to get any .d.ts files to behave correctly, you actually are best off doing this:

let $exports = module.exports;
export default $exports;

you can read about this here: https://github.com/Microsoft/TypeScript/issues/16442

like image 139
Alexander Mills Avatar answered Nov 13 '22 18:11

Alexander Mills