Skip to content

Commit

Permalink
Fix "Class constructor XXX cannot be invoked without 'new'" when in E…
Browse files Browse the repository at this point in the history
…SM5 js in Vuew and React.
  • Loading branch information
roug3-identy committed Jan 16, 2024
1 parent 2cd2e00 commit b8dfe70
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/decorators/auto-injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
isTransformDescriptor
} from "../providers/injection-token";
import {formatErrorCtor} from "../error-helpers";
import {__extends} from "tslib";

/**
* Class decorator factory that replaces the decorated class' constructor with
Expand All @@ -18,10 +19,16 @@ import {formatErrorCtor} from "../error-helpers";
function autoInjectable(): (target: constructor<any>) => any {
return function(target: constructor<any>): constructor<any> {
const paramInfo = getParamInfo(target);

return class extends target {
constructor(...args: any[]) {
super(
return (function(_super): any {
function extendedClazz(...args: any[]) {

Check warning on line 23 in src/decorators/auto-injectable.ts

View workflow job for this annotation

GitHub Actions / build (8.x)

Missing return type on function

Check warning on line 23 in src/decorators/auto-injectable.ts

View workflow job for this annotation

GitHub Actions / build (10.x)

Missing return type on function

Check warning on line 23 in src/decorators/auto-injectable.ts

View workflow job for this annotation

GitHub Actions / build (12.x)

Missing return type on function
const SuperProxy = new Proxy(_super, {
// target = Foo
apply(target, _, argumentsList) {
return new target(...argumentsList);
}
});
return SuperProxy.call(
null,
...args.concat(
paramInfo.slice(args.length).map((type, index) => {
try {
Expand Down Expand Up @@ -62,7 +69,9 @@ function autoInjectable(): (target: constructor<any>) => any {
)
);
}
};
__extends(extendedClazz, _super);
return extendedClazz;
})(target);
};
}

Expand Down

0 comments on commit b8dfe70

Please sign in to comment.