Skip to content

Commit

Permalink
feat: Expose typings for decorability, tags and di.context
Browse files Browse the repository at this point in the history
This are debatably internal concepts of injectable, and better
abstractions can replace them in the future.

I could not figure out a way to declare module/namespace for "Injectable"
so that the external concept of "tags" could be TS-merged with an external
interface.
  • Loading branch information
Iku-turso committed Sep 1, 2022
1 parent 3126248 commit fb49104
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/injectable/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface Injectable<
injectionToken?: InjectionToken<InjectionTokenInstance, InstantiationParam>;
instantiate: Instantiate<InjectionInstance, InstantiationParam>;
lifecycle: ILifecycle<InstantiationParam>;
decorable?: boolean;
tags?: any[];
}

type InjectableLifecycle<InstantiationParam> = InstantiationParam extends void
Expand Down Expand Up @@ -117,11 +119,17 @@ interface InjectMany {
): InjectionInstance[];
}

interface ContextItem {
injectable: Injectable<any, any, any>;
instantiationParameter: unknown;
}

export interface DiContainerForInjection {
inject: Inject;
injectMany: InjectMany;
register(...injectables: Injectable<any, any, any>[]): void;
deregister(...injectables: Injectable<any, any, any>[]): void;
context: ContextItem[];
}

export interface ILifecycle<InstantiationParam> {
Expand All @@ -145,4 +153,18 @@ export const lifecycleEnum: {
};
};

type Decorator = InjectionToken<
{ decorate: (toBeDecorated) => typeof toBeDecorated },
unknown
>;

type TargetableDecorator = Decorator & {
target?: Injectable<any, any, any> | InjectionToken<any, any>;
};

export const injectionDecoratorToken: TargetableDecorator;
export const instantiationDecoratorToken: TargetableDecorator;
export const registrationDecoratorToken: Decorator;
export const deregistrationDecoratorToken: Decorator;

export function createContainer(containerId: string): DiContainer;

0 comments on commit fb49104

Please sign in to comment.