Created
July 14, 2020 19:59
-
-
Save dzucconi/f382be6d101ec6e9cf1abb3f386a54e9 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
type Omit = <T extends object, K extends Array<keyof T>>( | |
obj: T, | |
keys: K | |
) => { [K2 in Exclude<keyof T, K[number]>]: T[K2] } | |
/** | |
* Removes entries from an object based on a list of keys | |
*/ | |
export const omit: Omit = (obj, keys) => { | |
const next = {} as { [K in keyof typeof obj]: (typeof obj)[K] } | |
let key: keyof typeof obj | |
for (key in obj) { | |
if (!keys.includes(key)) { | |
next[key] = obj[key] | |
} | |
} | |
return next | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment