From fb491045b93b28f15e372d153aa97f94fc7d093c Mon Sep 17 00:00:00 2001 From: Iku-turso Date: Thu, 1 Sep 2022 14:19:25 +0300 Subject: [PATCH] feat: Expose typings for decorability, tags and di.context 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. --- packages/injectable/index.d.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/injectable/index.d.ts b/packages/injectable/index.d.ts index a4624309..b131bba6 100644 --- a/packages/injectable/index.d.ts +++ b/packages/injectable/index.d.ts @@ -48,6 +48,8 @@ export interface Injectable< injectionToken?: InjectionToken; instantiate: Instantiate; lifecycle: ILifecycle; + decorable?: boolean; + tags?: any[]; } type InjectableLifecycle = InstantiationParam extends void @@ -117,11 +119,17 @@ interface InjectMany { ): InjectionInstance[]; } +interface ContextItem { + injectable: Injectable; + instantiationParameter: unknown; +} + export interface DiContainerForInjection { inject: Inject; injectMany: InjectMany; register(...injectables: Injectable[]): void; deregister(...injectables: Injectable[]): void; + context: ContextItem[]; } export interface ILifecycle { @@ -145,4 +153,18 @@ export const lifecycleEnum: { }; }; +type Decorator = InjectionToken< + { decorate: (toBeDecorated) => typeof toBeDecorated }, + unknown +>; + +type TargetableDecorator = Decorator & { + target?: Injectable | InjectionToken; +}; + +export const injectionDecoratorToken: TargetableDecorator; +export const instantiationDecoratorToken: TargetableDecorator; +export const registrationDecoratorToken: Decorator; +export const deregistrationDecoratorToken: Decorator; + export function createContainer(containerId: string): DiContainer;