Skip to content

Instantly share code, notes, and snippets.

@lightningspirit
Created January 28, 2022 00:30
Show Gist options
  • Save lightningspirit/1739e2b11f306ea9ee9f7b8b3791970c to your computer and use it in GitHub Desktop.
Save lightningspirit/1739e2b11f306ea9ee9f7b8b3791970c to your computer and use it in GitHub Desktop.
TypeScript Omit function
interface Omit {
<T extends Record<string, any>, K extends [...(keyof T)[]]>(
obj: T,
...keys: K
): {
[K2 in Exclude<keyof T, K[number]>]: T[K2]
}
}
const omit: Omit = (obj, ...props) => {
const result = { ...obj }
props.forEach(function (prop) {
delete result[prop]
})
return result
}
export default omit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment