*handle property being a getter

This commit is contained in:
Derrick Hammer 2023-03-24 15:16:53 -04:00
parent 99ea588c8b
commit 433a2d3516
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 13 additions and 4 deletions

View File

@ -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) {
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") { 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);
}; };
}, },