0
0
Typescriptprogramming~10 mins

Basic mapped type syntax 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 mapped type that makes all properties optional.

Typescript
type PartialType<T> = { [P in keyof T][1] };
Drag options to blanks, or click blank then click option'
A:
B!
C?
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using ':' instead of '?' which defines the type but does not make it optional.
Using '!' which is a non-null assertion and not valid here.
2fill in blank
medium

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

Typescript
type ReadonlyType<T> = { [1] [P in keyof T]: T[P] };
Drag options to blanks, or click blank then click option'
Areadonly
Boptional
Cmutable
Dprivate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'optional' which is not a TypeScript keyword.
Using 'private' which is an access modifier but not valid in mapped types.
3fill in blank
hard

Fix the error in the mapped type that tries to change all properties to string type.

Typescript
type Stringify<T> = { [P in keyof T]: [1] };
Drag options to blanks, or click blank then click option'
Aboolean
BT[P]
Cnumber
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'T[P]' which keeps the original type instead of changing it.
Using 'number' or 'boolean' which changes the type but not to string.
4fill in blank
hard

Fill both blanks to create a mapped type that makes all properties optional and readonly.

Typescript
type OptionalReadonly<T> = { [1] [P in keyof T][2]: T[P] };
Drag options to blanks, or click blank then click option'
Areadonly
B?
C!
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Placing '?' before the property name instead of after.
Using '!' which is not valid here.
5fill in blank
hard

Fill all three blanks to create a mapped type that changes all properties to readonly, optional, and of type number.

Typescript
type ReadonlyOptionalNumber<T> = { [1] [P in keyof T][2]: [3] };
Drag options to blanks, or click blank then click option'
Areadonly
B?
Cnumber
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' instead of 'number' for the property type.
Omitting '?' which makes properties required.