Skip to content

optionalLazyInject

@tsed/di

Usage

typescript
import { optionalLazyInject } from "@tsed/di";

See /packages/di/src/common/fn/lazyInject.ts.

Overview

ts
function optionalLazyInject<Token>(factory: () => Promise<{
    default: TokenProvider;
}>): Promise<Token | undefined>;

Description

Attempt to lazily load and inject a provider, returning undefined on failure.

Similar to lazyInject but catches errors and returns undefined instead of throwing. Useful for optional dependencies that may not be available.

Usage

typescript
import {optionalLazyInject} from "@tsed/di";

// Try to load optional plugin
const plugin = await optionalLazyInject(() => import("./optional/Plugin"));

if (plugin) {
  plugin.activate();
}

default

ts
default: TokenProvider;

Released under the MIT License.