I have a JavaScript class defined as:
// MyClass.js
module.exports = class MyClass {
//...
}
This is imported elsewhere as:
// otherModule.js
const MyClass = require('./MyClass');
I’m trying to convert MyClass
to TypeScript, so it’s now defined as:
// MyClass.ts
class MyClass {
// ...
}
export default MyClass;
I need to continue to import this using the require
syntax in JavaScript files, however do so I need to do either:
// otherModule.js
const MyClass = require('./MyClass').default;
// or
const { default: MyClass } = require('./MyClass');
Is there any way I can avoid having to explicitly specify that I’m importing default
? Ideally I’d want to continue importing this with const MyClass = require('./MyClass');
, if possible, even if this means I need to change how my TypeScript class is defined/exported.