reactant-di
Version:
A dependency injection lib for Reactant
43 lines • 1.08 kB
TypeScript
import { ServiceIdentifier } from '../interfaces';
/**
* ## Description
*
* You can use `@optional()` to decorate an optionally injected module.
*
* If other modules have no relevant dependency injection or are also optionally injected, the module will not be injected by default unless the injected module is imported in the `modules` parameter.
*
* ## Example
*
* ```ts
* @injectable()
* class Bar {
* getValue() {
* return 'bar';
* }
* }
*
* @injectable()
* class Foo {
* getValue() {
* return 'foo';
* }
* }
*
* @injectable()
* class FooBar {
* constructor(@optional() public bar: Bar, @optional('foo') public foo: Foo) {}
* }
*
* const fooBar = testBed({
* modules: [
* { provide: 'foo', useClass: Foo },
* ],
* main: FooBar,
* });
*
* expect(fooBar.instance.foo.getValue()).toBe('foo');
* expect(fooBar.fooBar.bar).toBeUndefined();
* ```
*/
export declare function optional(serviceIdentifier?: ServiceIdentifier<any>): (target: object, key?: string, index?: number) => void;
//# sourceMappingURL=optional.d.ts.map