'Nested interfaces / types across multiple files?
I currently have a backend / frontend application that uses a shared types folder which contains all of the request / response body interfaces. As the application has grown, we're ending up with some comically long interface names such as ShippingPlateListShippingPlateStatusRequest or ShippingPlateListShippingPlateStatusResponseBody. While not the end of the world and auto-complete definitely helps they're still pretty hard to read at a glance.
Ideally, I could refactor this so we could just import ShippingPlate and then reference it like this: ShippingPlate.List.ShippingPlateStatus.Request or ShippingPlate.List.ShippingPlateStatus.Response.Body.
Namespaces seem to fit the bill for this, however the interfaces are all kept in separate files. For the interfaces I mentioned, along with interfaces for two other request/response pairs it looks something like this:
types/shipping-plate/list/shipping-plate-status/index.ts
types/shipping-plate/list/shipping-plate-status/request.interface.ts
types/shipping-plate/list/shipping-plate-status/response.interface.ts
types/shipping-plate/list/shipping-plate-type/index.ts
types/shipping-plate/list/shipping-plate-type/request.interface.ts
types/shipping-plate/list/shipping-plate-type/response.interface.ts
types/shipping-plate/list/index.ts
types/shipping-plate/shipping-plate/index.ts
types/shipping-plate/shipping-plate/request.interface.ts
types/shipping-plate/shipping-plate/response.interface.ts
types/shipping-plate/index.ts
Aside from namespaces, which seemed to cause more problems than it was worth (this is a fully ES Module code base), is there any way to make this work across multiple files? Is there another approach I can take that would make this work?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
