I am trying to organize my TS project, and I have moved most of my classes and interfaces in to a /models
directory. In an effort to make things easier on myself/future developers, I figured making a toplevel models.ts
file that imported all the models and then reexported them would make things easier.
To that end, I thought of making a namespace/module called Models
and then exporting that namespace/module. However, I ran in to issues trying to link up what I had imported in to the exported module, like so:
import {Args} from "./models/args";
import {Response} from "./models/response";
import {Inventory} from "./models/inventory";
export module Models {
// Trying things like:
// this.Args = Args --- nope, not a class
// Args = Args -- nope
// export Args -- nope
// export class Args -- nope
// export class ArgsModel extends Args -- nope
//
// This works, but it's renaming, and it feels hackish.
export class ArgsModel extends Args {}
//
// import export Args from "./models/args" -- nope, cant import from within a module
}
Searching for a while, I found a lot of information about modules, but nothing that addressed this in particular, which has made me realize this is probably not a pattern TS uses. To that end, I found a similar question asked here How to export multiple imported classes as a module that yielded an answer suggesting to do something like this:
export * from "./models/args"
export * from "./models/response"
export * from "./models/inventory"
However, I also feel I've gone so far down this rabbit hole that I want to figure out how I would go about my original intention simply so I can understand typescript a bit better.
How would one export a single namespace that contained classes, interfaces, and modules that have been imported?