0
0
Typescriptprogramming~10 mins

Why utility types are needed in Typescript - Test Your Understanding

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 makes all properties optional.

Typescript
type PartialUser = [1]<User>;
Drag options to blanks, or click blank then click option'
ARequired
BReadonly
CPartial
DPick
Attempts:
3 left
💡 Hint
Common Mistakes
Using Required instead of Partial, which makes all properties required.
Using Readonly which makes properties immutable, not optional.
2fill in blank
medium

Complete the code to create a type that makes all properties required.

Typescript
type CompleteUser = [1]<User>;
Drag options to blanks, or click blank then click option'
APartial
BPick
CReadonly
DRequired
Attempts:
3 left
💡 Hint
Common Mistakes
Using Partial which makes properties optional instead of required.
Using Readonly which only changes mutability.
3fill in blank
hard

Fix the error in the code to create a type with only the 'name' property from User.

Typescript
type UserName = [1]<User, 'name'>;
Drag options to blanks, or click blank then click option'
ARequired
BPick
CPartial
DOmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using Omit which excludes properties instead of selecting.
Using Partial or Required which change optionality, not selection.
4fill in blank
hard

Fill both blanks to create a type that excludes 'password' and makes remaining properties readonly.

Typescript
type SafeUser = [1]<[2]<User, 'password'>>;
Drag options to blanks, or click blank then click option'
AReadonly
BPartial
COmit
DPick
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order of utility types.
Using Pick instead of Omit which selects properties instead of excluding.
5fill in blank
hard

Fill all three blanks to create a type that makes 'email' optional, picks 'name' and 'email', and makes them readonly.

Typescript
type CustomUser = [1]<[2]<User, 'name' | 'email'>> & { email?: [3] };
Drag options to blanks, or click blank then click option'
AReadonly
BPick
Cstring
DPartial
Attempts:
3 left
💡 Hint
Common Mistakes
Using Partial instead of Pick for selection.
Not overriding 'email' to be optional.