@triviality/core
Version:
Purely typed service container
20 lines (19 loc) • 1.23 kB
TypeScript
export declare type ServiceFactory<T = unknown> = () => T;
export declare type SF<T = unknown> = ServiceFactory<T>;
export declare const assetServiceFactory: (sf: unknown) => sf is ServiceFactory<unknown>;
export declare const isServiceFactory: (target: unknown) => target is ServiceFactory<unknown>;
export declare const serviceOfServiceFactory: <T>(sf: ServiceFactory<T>) => T;
export declare const serviceOfServiceFactories: <T>(factories: ServiceFactory<T>[]) => T[];
export declare type ServicesAsFactories<Services> = {
[K in keyof Services]: SF<Services[K]>;
};
export declare type ServiceTag = string;
export declare const assertServiceTag: (tag: unknown) => tag is string;
export declare type TagServicePair<T = unknown> = [ServiceTag, SF<T>];
export declare const isServiceTag: (target: unknown) => target is string;
export declare type ServiceFactoryByTag<T = unknown> = (tag: ServiceTag) => SF<T>;
export declare type ServicesOfType<Services, TType> = {
[K in keyof Services]: Services[K] extends TType ? Services[K] : never;
};
export declare type ServiceKeysOfType<Services, TType> = keyof ServicesOfType<Services, TType>;
export declare const AllAsServiceFactory: <T>(instances: T[]) => ServiceFactory<T>[];