Skip to content

Instantly share code, notes, and snippets.

@kerren
Created March 25, 2021 10:14
Show Gist options
  • Save kerren/fa3a5f0f7885af8d87989a39e2d692e8 to your computer and use it in GitHub Desktop.
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
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