Is there a way to convert a deeply nested class object into a plain Object
type while still retaining methods like getters and setters?
class A {
id = "";
data = {
sync: {}
};
}
class SyncService {
syncResultServiceA = {
ToSync: 0,
Synced: 0,
SyncErrors: [],
};
syncResultServiceB = {
ToSync: 0,
Synced: 0,
Errors: [],
};
}
const a = new A();
a.data.sync = new SyncService();
console.log(a.data.sync.constructor.name) // "SyncService"
I've tried various solutions, like using {...obj}
which doesn't work for nested class objects, or using JSON.stringify() + parse()
which removes custom methods.