remarks export function deepClone < T extends object > ( objToClone ) { return clone ( objToClone ) as T ; function clone ( obj ) { const newObj = Object . create ( obj . constructor . prototype ) as object ; for ( const propName of Object . keys ( obj ) ) ( newObj as any ) [ propName ] = cloneItem ( ( obj as any ) [ propName ] ) ; return newObj ; } function cloneArray ( array ) { return array . map ( cloneItem ) ; } function cloneItem ( item ) { if ( item instanceof Array ) return cloneArray ( item ) ; else if ( typeof item === "object" ) return item === null ? item : clone ( item ) ; return item ; } }