njct
Version:
Inject a dependency
31 lines (29 loc) • 1.19 kB
TypeScript
declare function provide(token: any, mock: () => any): void;
declare function provideClass(token: any, ctor: any): void;
declare function clear(): void;
/**
* Inject a dependency instance of a class
* @param ctor Constructable class reference
* @returns The instance of the class or a mock object if the dependency was mocked using mock()
*/
declare function inject<T extends new (...arguments_: any[]) => any>(ctor: T): T;
/**
* Inject a dependency of primitive value
* @param token The injection token
* @param value Primitive value
* @returns The dependency or a mock value if the dependency was mocked using mock()
*/
declare function inject<T extends string | number | boolean | symbol | bigint | null | undefined>(token: any, value: T): T;
/**
* Inject a dependency
* @param token The injection token
* @param factory Factory function that returns the dependency
* @returns The dependency or a mock object if the dependency was mocked using mock()
*/
declare function inject<T>(token: any, factory?: () => T): T;
declare const injector: {
provideClass: typeof provideClass;
provide: typeof provide;
clear: typeof clear;
};
export { inject, injector };