Created
March 25, 2021 10:14
-
-
Save kerren/fa3a5f0f7885af8d87989a39e2d692e8 to your computer and use it in GitHub Desktop.
[Partial types] An example where we don't need the whole item #types #partial #typescript
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
class Person { | |
name: string; | |
surname: string; | |
email: string; | |
age: number; | |
uuid: string; | |
}; | |
async function confirmSurname(person: Partial<Person>) { | |
if (!person.email) { | |
throw new Error(`Trying to confirm surname of person ${person.uuid} but no email address was sepecified`); | |
} | |
const message = `Hi ${person.name || 'there'}, you've set your surname to ${person.surname || 'an empty string..'}. Are you sure this is correct?`; | |
return await externalEmailService.sendMessage(person.email, message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment