Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const untrackDeep = (obj: T) => {
if (typeof obj !== 'object' || obj === null) return obj;
const untrackedObj = getUntrackedObject(obj);
if (untrackedObj !== null) return untrackedObj;
const newObj = {} as T;
let modified = false;
Object.entries(obj).forEach(([k, v]) => {
const vv = untrackDeep(v);
if (vv !== null) {
newObj[k as keyof T] = vv;
modified = true;
} else {
newObj[k as keyof T] = v;
}
});
return modified ? newObj : obj;
};