Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The question mark (?) after the property name makes the property optional in a mapped type.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The 'readonly' keyword before the property makes all properties readonly in the mapped type.
3fill in blank
hardFix 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'
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.
✗ Incorrect
To change all property types to string, use 'string' as the type for each property.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Placing '?' before the property name instead of after.
Using '!' which is not valid here.
✗ Incorrect
Use 'readonly' before the property name and '?' after it to make properties readonly and optional.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' instead of 'number' for the property type.
Omitting '?' which makes properties required.
✗ Incorrect
Use 'readonly' before the property name, '?' after it, and set the type to 'number' to achieve the desired mapped type.