I’m creating a TypeScript library that contains various interfaces and types for other projects to use. My project has a complex folder structure where I organize everything by functionality (like user-management, data-processing, etc) and then by type (models, services, controllers).
The problem is that I have to manually add every single export to my main index.ts file whenever I create new types or interfaces. This is getting really tedious as my library grows.
Is there a standard way to automatically export all TypeScript definitions from multiple files without having to write a custom build script? I’m looking for something that can scan all my .ts files and create the exports automatically.
Right now my index file looks messy with dozens of export statements and I keep forgetting to add new ones when I create new interfaces.
I use export * from ‘./path’ with a clean folder structure. Created an exports directory at the root and group related stuff into files like types.ts, interfaces.ts, utils.ts. Each file uses wildcard exports to grab everything from their source directories. Your main index.ts just exports from these consolidated files instead of tracking individual interfaces. I also have an npm script that runs grep to catch any new exported types I might’ve missed. Not fully automated but cuts down the manual work and keeps things organized.
have u tried using barrel exports? just make index.ts files in each folder that do the exporting, then ur main index just imports from those. way less clutter and easier to keep up with new stuff!
I set up a simple Node.js script that runs during my build process. It walks through all my TypeScript files, finds exported interfaces and types using regex, then auto-generates the index.ts file. I added it as a prebuild step in package.json so it runs before compilation. The trick is making sure it only grabs actual exports and ignores internal types. Takes maybe 30 seconds to set up but saves hours of maintenance. You could also check out ts-morph if you want something more robust than regex, but honestly a basic file walker script works fine for me.