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