Skip to content

Instantly share code, notes, and snippets.

@michaeljscript
Last active July 2, 2019 14:58
Show Gist options
  • Save michaeljscript/884002dc3db7a8356c4e18577a2b8ef6 to your computer and use it in GitHub Desktop.
Save michaeljscript/884002dc3db7a8356c4e18577a2b8ef6 to your computer and use it in GitHub Desktop.
function getFlatObjectDifferencet<T extends object>(newOne: T, oldOne: T, compare: (newOne: T, oldOne: T, key: keyof T) => boolean): Partial<T> {
const allKeys: Array<keyof T> = Object.keys(newOne);
const uniqueKeys = allKeys.filter((key) => compare(newOne, oldOne, key));
return Object.assign({}, ...uniqueKeys.map(k => ({[k]: newOne[k]})));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment