Created
January 28, 2022 00:30
-
-
Save lightningspirit/1739e2b11f306ea9ee9f7b8b3791970c to your computer and use it in GitHub Desktop.
TypeScript Omit function
This file contains hidden or 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
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