Created
April 4, 2021 04:38
-
-
Save njbmartin/9e4a9be5354b488e546ccf5fa5e8d6de 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
const person = { | |
firstName: "Jane", | |
lastName: "Bloggs", | |
email: "jane@example.com", | |
phone: "0123456789" | |
}; | |
const omitKey = <T, K extends keyof T>(data: T, key: K) => { | |
const { [key]: _, ...o } = data; | |
return o; | |
} | |
console.log(person); | |
// expected output: email is a property | |
const personWithoutEmail = omitKey(person, "email") | |
console.log(personWithoutEmail) | |
// expected output: email is not a property | |
// actual output: email is not a property and not part of the object... yay! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment