From 81fb7f0071596e436d0bdf3bb5121be2dcbb92ec Mon Sep 17 00:00:00 2001 From: "Max P." Date: Wed, 2 Apr 2025 21:45:41 +0200 Subject: [PATCH] refactor(inject): rename `necessary` parameter to `isNecessary` for clarity --- src/decorators/Inject.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/decorators/Inject.ts b/src/decorators/Inject.ts index 1401bbd..cbfb341 100644 --- a/src/decorators/Inject.ts +++ b/src/decorators/Inject.ts @@ -17,7 +17,7 @@ import { InitDelegate } from '../types/InitDelegate.js'; * @param init Optional an initializer function to transform the dependency before injection * or true to instantiate the dependency if it has a constructor. * @see {@link InitDelegate} for more information on initializer functions. - * @param necessary If true, throws an error if the dependency is not found. + * @param isNecessary If true, throws an error if the dependency is not found. * @returns The resolved dependency or undefined if the dependency is not necessary * and not found, or throws an error if the dependency is necessary and not found. * @throws **Only throws errors if the dependency is necessary.** @@ -43,7 +43,7 @@ import { InitDelegate } from '../types/InitDelegate.js'; export function Inject( identifier: Identifier, init?: InitDelegate | true, - necessary = true, + isNecessary = true, ) { return function (target: unknown, propertyKey: string | symbol): void { /** @@ -52,7 +52,7 @@ export function Inject( * @returns The resolved dependency or undefined if the dependency is not found. */ const resolve = (): T | undefined => { - return TSinjex.getInstance().resolve(identifier, necessary); + return TSinjex.getInstance().resolve(identifier, isNecessary); }; Object.defineProperty(target, propertyKey, { @@ -61,7 +61,7 @@ export function Inject( const dependency: T | undefined = tryAndCatch( () => resolve(), - necessary, + isNecessary, identifier, DependencyResolutionError, ); @@ -78,13 +78,13 @@ export function Inject( else if (initFunction != null) instance = tryAndCatch( initFunction, - necessary, + isNecessary, identifier, InitializationError, ); - else if (necessary) + else if (isNecessary) throw new NoInstantiationMethodError(identifier); - } else if (necessary) + } else if (isNecessary) throw new DependencyResolutionError(identifier); /**