Welcome! Today, we will explore creating a simple address book application using TypeScript's Map
. This task will help you understand how to manipulate Map
in TypeScript, focusing on adding, retrieving, and deleting entries. By the end of this lesson, you'll have a solid grasp of these fundamental operations while ensuring data integrity through the type annotations that TypeScript provides.
In this task, we will implement three methods to manage our address book, using type annotations to ensure code reliability:
addContact(name: string, phoneNumber: string): boolean
: Adds a new contact. Returnsfalse
if the contact already exists; otherwise, it adds the contact and returnstrue
. In this task, let's assume phone numbers do not change, so it's not allowed to overwrite the existing contact's number.getContact(name: string): string | undefined
: Retrieves the phone number for a givenname
. Returnsundefined
if the contact does not exist.deleteContact(name: string): boolean
: Deletes a contact with the givenname
. Returns if the contact exists and is deleted, otherwise.
