Skip to content

Instantly share code, notes, and snippets.

@Gummiees
Created October 29, 2020 09:46
Show Gist options
  • Save Gummiees/cb9e84e9f5b10348c753cff30fab8d4a to your computer and use it in GitHub Desktop.
Save Gummiees/cb9e84e9f5b10348c753cff30fab8d4a to your computer and use it in GitHub Desktop.
Duplicates the content from a source to a target, both being the same type
/**
*
* Duplica el contenido de un objeto sobre otro del mismo tipo.
*
* @param source Objeto a partir de cual obtener los valores
* @param destiny Objeto al cual asignar dichos valores
*/
mapAll<T>(source: T, destiny: T) {
const keys: any[] = Object.keys(source);
keys.forEach((key) => {
if (source[key] instanceof Object && !(source[key] instanceof Date)) {
this.mapAll<T>(source[key], destiny[key]);
} else {
destiny[key] = source[key];
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment