I have a large number of TypeScript modules that I need to export in a specific way so that their types are also available without errors, similar to how it's done in Node.JS. Here is an example of how I'm currently doing it:
export * from './clans';
export * from './clans.dto';
export * from './defferedActions';
export * from './defferedActions.dto';
export * from './eventRooms';
export * from './eventRooms.dto';
...
export const list = [
'clans', 'defferedActions', 'eventRooms', ...
];
In NodeJS, I could use require to automatically export modules, but this approach does not work in TypeScript. Here's an example of how I would do it in NodeJS:
const fs = require('fs');
const path = require('path');
const modulesDir = path.join(__dirname, 'modules');
const modules = fs.readdirSync(modulesDir);
modules.forEach((module) => {
if (module.endsWith('.js')) {
const name = module.slice(0, -3);
module.exports[name] = require(path.join(modulesDir, module));
}
});
const list = modules.map((module) => module.slice(0, -3));
I'm looking for suggestions on how to automatically export my TypeScript modules so that their types are also available without errors.