Last active
July 2, 2019 14:58
-
-
Save michaeljscript/884002dc3db7a8356c4e18577a2b8ef6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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