Skip to content

Instantly share code, notes, and snippets.

@dzucconi
Created July 14, 2020 19:59
Show Gist options
  • Save dzucconi/f382be6d101ec6e9cf1abb3f386a54e9 to your computer and use it in GitHub Desktop.
Save dzucconi/f382be6d101ec6e9cf1abb3f386a54e9 to your computer and use it in GitHub Desktop.
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