Consider a nested object like below
class Person {
name: string = 'name';
address: {street: string, pincode: string} = {street: 'street', pincode: '44555'};
}
There is a utility function(undefinedAllLeadNodes) which undefines all leaf nodes. So passing a new Person() creates below
person.name = undefined
person.address.street = undefined;
person.address.pincode = undefined;
If i declare as below
export function undefineAllLeafProperties<
T extends object
>(obj : T) : {[key: string] : any} {
...undefine all leaf nodes here
}
It shows compilation error for person.address.street and it sounds fine for {[key: string] : any}
return type declaration.
But What can be the proper return type for the utility function(undefinedAllLeadNodes) so that i can access it like below without any errors
person.address.street = 'update only street';