*handle property being a getter
This commit is contained in:
parent
99ea588c8b
commit
433a2d3516
17
src/index.ts
17
src/index.ts
|
@ -137,15 +137,24 @@ export const factory = function <T extends Client = Client>(
|
|||
return function (...args: any): T {
|
||||
return new Proxy<T>(new type(...args), {
|
||||
get(target: T, property: string) {
|
||||
const prop = target[property as keyof T];
|
||||
let desc = Object.getOwnPropertyDescriptor(
|
||||
target?.constructor?.prototype,
|
||||
property
|
||||
);
|
||||
if (!desc?.get) {
|
||||
const prop = target[property as keyof T];
|
||||
|
||||
if (typeof prop !== "function") {
|
||||
return prop;
|
||||
if (typeof prop !== "function") {
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
|
||||
return async (...args: any[]): Promise<any> => {
|
||||
await target.loadLibs(module);
|
||||
|
||||
if (desc?.get) {
|
||||
return target[property as keyof T];
|
||||
}
|
||||
|
||||
return (target[property as keyof T] as Function)(...args);
|
||||
};
|
||||
},
|
||||
|
|
Reference in New Issue