Function: optional()
optional<
K>(key):OptionalDependency<K>
Defined in: src/dependencies.ts:28
Marks a dependency as optional: the factory receives the service when it is registered, and undefined otherwise.
Type Parameters
K
K extends ServiceKey
Parameters
key
K
Returns
Example
ts
container.addSingleton(
'mailer',
(transport) => new Mailer(transport ?? consoleTransport),
[optional('transport')],
);