0
0
Typescriptprogramming~10 mins

Pick type in Typescript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a type that picks only the 'name' property from the User type.

Typescript
type User = { name: string; age: number; email: string };
type UserName = Pick<User, [1]>;
Drag options to blanks, or click blank then click option'
A"email"
B"age"
C"name"
D"address"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the property name in quotes.
Using a property name that does not exist in the original type.
2fill in blank
medium

Complete the code to pick both 'name' and 'email' properties from the User type.

Typescript
type User = { name: string; age: number; email: string };
type ContactInfo = Pick<User, [1]>;
Drag options to blanks, or click blank then click option'
A"name" | "email"
B"age" | "email"
C"name"
D"email"
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of pipes to separate keys.
Including keys that are not part of the original type.
3fill in blank
hard

Fix the error in the code to correctly pick the 'age' property from the Person type.

Typescript
type Person = { name: string; age: number; location: string };
type PersonAge = Pick<Person, [1]>;
Drag options to blanks, or click blank then click option'
A"age"
Bnumber
CPerson["age"]
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Not putting the property name in quotes.
Using the property type instead of the property name.
4fill in blank
hard

Fill all three blanks to create a type that picks 'title' and 'completed' from the Task type.

Typescript
type Task = { id: number; title: string; completed: boolean };
type TaskSummary = Pick<Task, [1] [2] [3]>;
Drag options to blanks, or click blank then click option'
A"title"
B|
C"completed"
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using ampersand & instead of pipe |.
Not putting keys in quotes.
5fill in blank
hard

Fill all three blanks to create a type that picks 'username' and 'email' from the Account type.

Typescript
type Account = { username: string; email: string; password: string; isActive: boolean };
type AccountInfo = Pick<Account, [1] [2] [3]>;
Drag options to blanks, or click blank then click option'
A"username"
B|
C"email"
D"isActive"
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of pipes.
Forgetting quotes around keys.