0
0
Typescriptprogramming~15 mins

Type alias for objects in Typescript - Mini Project: Build & Apply

Choose your learning style9 modes available
Type Alias for Objects in TypeScript
📖 Scenario: You are building a simple contact list app. Each contact has a name and an email.To keep your code clean and easy to understand, you want to create a type alias for the contact object.
🎯 Goal: Create a type alias called Contact for an object with name and email properties, then create a variable using this type and print the contact's details.
📋 What You'll Learn
Create a type alias called Contact with name and email as string properties
Create a variable called myContact of type Contact with name 'Alice' and email 'alice@example.com'
Print the contact's name and email using console.log
💡 Why This Matters
🌍 Real World
Type aliases help keep code organized and clear when working with objects like user profiles, settings, or data records.
💼 Career
Understanding type aliases is important for writing clean, maintainable TypeScript code in many software development jobs.
Progress0 / 4 steps
1
Create the Contact type alias
Create a type alias called Contact for an object with two string properties: name and email.
Typescript
Need a hint?

Use the type keyword followed by the alias name and an object shape with properties.

2
Create a variable of type Contact
Create a variable called myContact of type Contact and assign it an object with name set to 'Alice' and email set to 'alice@example.com'.
Typescript
Need a hint?

Use const myContact: Contact = { name: 'Alice', email: 'alice@example.com' };

3
Print the contact's name and email
Use console.log to print the contact's name and email from the myContact variable in the format: Name: Alice, Email: alice@example.com.
Typescript
Need a hint?

Use a template string with backticks and ${} to insert variables.

4
Run the program to see the output
Run the program and observe the output printed to the console.
Typescript
Need a hint?

The console should show the contact's name and email exactly as formatted.