fix: Try another api
This commit is contained in:
@@ -49,7 +49,10 @@ export function Inject<TargetType, DependencyType, PropertyType>(
|
||||
return function (
|
||||
constructor: undefined,
|
||||
context: ClassFieldDecoratorContext<TargetType>,
|
||||
): void {
|
||||
): (
|
||||
this: TargetType,
|
||||
initialValue: PropertyType | undefined,
|
||||
) => PropertyType | undefined {
|
||||
const _identifier = identifier ?? context.name;
|
||||
|
||||
if (_identifier == null && necessary === true)
|
||||
@@ -67,9 +70,10 @@ export function Inject<TargetType, DependencyType, PropertyType>(
|
||||
);
|
||||
};
|
||||
|
||||
context.addInitializer(function (this: TargetType) {
|
||||
Object.defineProperty(this, context.name, {
|
||||
get() {
|
||||
return function (
|
||||
this: TargetType,
|
||||
initialValue: PropertyType | undefined,
|
||||
): PropertyType | undefined {
|
||||
let instance: DependencyType | PropertyType | undefined;
|
||||
|
||||
const dependency: DependencyType | undefined = tryAndCatch(
|
||||
@@ -84,8 +88,7 @@ export function Inject<TargetType, DependencyType, PropertyType>(
|
||||
typeof init === 'function' && dependency != null
|
||||
? (): PropertyType => init(dependency)
|
||||
: init === true && hasConstructor(dependency)
|
||||
? (): PropertyType =>
|
||||
new dependency() as PropertyType
|
||||
? (): PropertyType => new dependency() as PropertyType
|
||||
: undefined;
|
||||
|
||||
if (init == null) instance = dependency;
|
||||
@@ -112,14 +115,9 @@ export function Inject<TargetType, DependencyType, PropertyType>(
|
||||
configurable: false,
|
||||
});
|
||||
|
||||
return instance;
|
||||
},
|
||||
/**
|
||||
* Make the property configurable to allow replacing it
|
||||
*/
|
||||
configurable: true,
|
||||
});
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return instance as any;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user