I am facing the challenge of exporting multiple models and services within a TypeScript module.
Origin
models/User.ts
import {IModel} from "./IModel";
export interface User extends IModel {
// ...
}
services/UserService.ts
import {inject} from 'aurelia-framework';
import {HttpClient} from 'aurelia-fetch-client';
import {BaseService} from "./BaseService";
import {User as ModelType} from "../models/User";
@inject(HttpClient)
export class UserService extends BaseService<ModelType> {
// ...
}
Output
This is how I envision the final product after project compilation. While not an exact replica, my goal is for the root module my-module
to have distinct sub-modules for models
and services
. This structure will prevent any potential naming conflicts between models and services.
dist/index.d.ts
declare module "my-module/models" {
export interface User { ... }
// ... other models here ...
}
declare module "my-module/services" {
export class UserService { ... }
// ... other services here ...
}
Ultimately, this package can be installed via npm
and utilized in another project like so:
import {User} from "my-module/models";
import {UserService} from "my-module/services";
- Due to the large number of models and services, manually maintaining an
index.ts
to handle them all would be inefficient. - What would be the best way to organize my TypeScript project to achieve this desired structure?