I am currently implementing a CMS that is based on different packages. It has a package for pages
, core
, files
, etc...
At the core of it all is a simple service registry, basically like this:
interface Service {}
let registry: {[key: string]: Service} = {};
export function get (name: string) : Service|null
{
return registry[name] || null;
}
Every package (core
, pages
, files
, ...) registers a bunch of different core services. So now I though I might be possible, so that every package automatically augments the core service container declaration and adds explicit overrides:
So core
can add:
declare module "..."
{
export namespace CMS
{
export interface Application
{
get(name: "confirm"): Confirm;
get(name: "date.formatter"): DateFormatter;
get(name: "fetch"): BackendFetch;
// ...
}
}
}
And pages
can add:
declare module "..."
{
export namespace CMS
{
export interface Application
{
get(name: "slug"): SlugGenerator;
// ...
}
}
}
etc...
Right now that doesn't seem to work. I get it to work that the own services are recognized in the current package, but never the external ones.
My setup:
- in every package the types are in
src/@types/filename.d.ts
. - TypeScript 3.6.4
What I would like:
- All the augmentations of all packages are automatically picked up
What I would like to avoid:
- That every package has to import all other packages that provides augmentations (because it should be as automatic as possible).