0
0
Typescriptprogramming~15 mins

Pick type in Typescript - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the Pick Type in TypeScript
📖 Scenario: You are working on a user management system. You have a full user profile object, but sometimes you only need a smaller part of that profile, like just the user's name and email.
🎯 Goal: Learn how to use the Pick type in TypeScript to create a new type with only selected properties from an existing type.
📋 What You'll Learn
Create a full user profile type with specific properties
Create a new type using Pick to select only some properties
Create a variable of the new picked type with exact properties
Print the picked user information to the console
💡 Why This Matters
🌍 Real World
In real projects, you often have big data objects but only need a small part for certain tasks, like showing user contact info or sending emails.
💼 Career
Understanding <code>Pick</code> helps you write cleaner, safer TypeScript code by reusing types and avoiding repetition.
Progress0 / 4 steps
1
Create a full user profile type
Create a TypeScript type called UserProfile with these exact properties: id as number, name as string, email as string, and age as number.
Typescript
Need a hint?

Use the type keyword to define a new type with the given properties and their types.

2
Create a picked user type with Pick
Create a new type called UserContact using Pick to select only the name and email properties from UserProfile.
Typescript
Need a hint?

Use Pick<OriginalType, "prop1" | "prop2"> to create a new type with only the chosen properties.

3
Create a variable of the picked type
Create a constant variable called contactInfo of type UserContact with name set to "Alice" and email set to "alice@example.com".
Typescript
Need a hint?

Define a constant with the picked type and assign the exact property values as strings.

4
Print the picked user information
Write a console.log statement to print the contactInfo variable.
Typescript
Need a hint?

Use console.log(contactInfo) to show the picked user information in the console.