I want to build such a function:
const recursionProxy = <T extends object>(subject: T) =>
new Proxy(subject, {
get(target, key: keyof T) {
const nestedSubject = target[key];
if (typeof nestedSubject === "object") {
return recursionProxy(nestedSubject);
}
return nestedSubject ?? target._ ?? "Message not set";
},
});
but under the line recursionProxy(nestedSubject); there is an error that says
[i] Argument of type 'T[keyof T]' is not assignable to parameter of type 'object'.
why typescript doesn't take that if staement in consideration,
in side the if statement nestedSubject is of type object