0
0
Typescriptprogramming~10 mins

Removing modifiers with minus 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 remove the 'readonly' modifier from the type.

Typescript
type Mutable<T> = [1] T;
Drag options to blanks, or click blank then click option'
Areadonly
B+readonly
C-readonly
Dreadonly-
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'readonly' instead of '-readonly' which adds the modifier instead of removing it.
Using '+readonly' which adds the modifier.
Placing the minus sign after 'readonly' which is invalid syntax.
2fill in blank
medium

Complete the code to remove the 'optional' modifier from all properties of type T.

Typescript
type RequiredProps<T> = { [P in keyof T]-[1]: T[P] };
Drag options to blanks, or click blank then click option'
A+?
B-?
C?
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+?' which adds the optional modifier.
Using '?' alone which does not remove the modifier.
Using duplicate '?' which is invalid.
3fill in blank
hard

Fix the error in the code to correctly remove the 'readonly' modifier from type T.

Typescript
type Writable<T> = { -[1] P in keyof T: T[P] };
Drag options to blanks, or click blank then click option'
Areadonly
Breadonly-
Creadonly?
Dreadonly+
Attempts:
3 left
💡 Hint
Common Mistakes
Placing the minus sign after 'readonly' which is invalid.
Adding '+' instead of '-' which adds the modifier.
Using 'readonly?' which is not valid here.
4fill in blank
hard

Fill both blanks to create a type that removes both 'readonly' and 'optional' modifiers from T.

Typescript
type FullyMutable<T> = { -[1] P in keyof T-[2]: T[P] };
Drag options to blanks, or click blank then click option'
Areadonly
B?
Dreadonly?
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving the second blank empty which does not remove optional.
Using '+readonly' which adds readonly instead of removing.
Using 'readonly?' which is invalid syntax.
5fill in blank
hard

Fill all three blanks to create a type that removes 'readonly' and 'optional' modifiers and converts keys to uppercase strings.

Typescript
type UppercaseMutable<T> = { -[1] [2] in keyof T as [3]: T[[2]] };
Drag options to blanks, or click blank then click option'
Areadonly
BP
CUppercase<string & P>
DK
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'K' instead of 'P' as the key variable.
Not removing readonly modifier.
Not transforming keys to uppercase.