Skip to main content
Module

x/momentum/di/decorators/optional.ts

Momentum is an open-source framework for building server-side Deno applications in TypeScript. It provides the paradigms and design patterns to guide developers to create robust, scalable, and enterprise-grade applications.
Latest
File
import { DiContainer, Type } from "../di-container.ts";
/** * Decorator use to mark an injected type as optional. If the type is not able to be resolved, the argument will be undefined */export function Optional(): PropertyDecorator & ParameterDecorator { return function ( // deno-lint-ignore ban-types target: Object, propName?: string | symbol, paramIndex?: number, ) { if (propName) { DiContainer.root().registerProperty( target.constructor as Type, propName.toString(), { isOptional: true }, ); } if (paramIndex || paramIndex === 0) { DiContainer.root().registerCtorParam(target as Type, paramIndex, { isOptional: true, }); } };}