Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a readonly property in the interface.
Typescript
interface User {
[1] id: number;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'const' inside interfaces is invalid.
Using 'static' or 'private' does not make properties readonly.
✗ Incorrect
The readonly keyword makes the property immutable after initialization.
2fill in blank
mediumComplete the code to create an interface with a readonly property 'name'.
Typescript
interface Person {
[1] name: string;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'private' instead of 'readonly'.
Forgetting to add any modifier.
✗ Incorrect
The readonly keyword ensures the 'name' property cannot be changed after assignment.
3fill in blank
hardFix the error in the interface by making the property 'age' readonly.
Typescript
interface Employee {
[1] age: number;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'const' inside interfaces.
Using 'private' or 'static' incorrectly.
✗ Incorrect
Only readonly is valid to make interface properties immutable.
4fill in blank
hardFill both blanks to declare a readonly property 'title' of type string in the interface.
Typescript
interface Book {
[1] [2]: string;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of keyword and property name.
Using 'private' or 'static' instead of 'readonly'.
✗ Incorrect
The property name is 'title' and it must be marked readonly to prevent changes.
5fill in blank
hardFill all three blanks to declare a readonly property 'id' of type number in the interface.
Typescript
interface Product {
[1] [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 type.
Omitting the readonly keyword.
✗ Incorrect
The property 'id' is marked readonly and typed as number.