Created
August 1, 2020 08:54
-
-
Save KonradSzwarc/f42d187532ec0b4cae81c9fa0ade48f6 to your computer and use it in GitHub Desktop.
Type-safe 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
export const omit = <T extends Record<string, unknown>, K extends [...(keyof T)[]]>( | |
originalObject: T, | |
keysToOmit: K, | |
): { | |
[K2 in Exclude<keyof T, K[number]>]: T[K2]; | |
} => { | |
const clonedObject = { ...originalObject }; | |
for (const path of keysToOmit) { | |
delete clonedObject[path]; | |
} | |
return clonedObject; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment