0
0
Typescriptprogramming~10 mins

Readonly properties in interfaces 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 declare a readonly property in the interface.

Typescript
interface User {
  [1] id: number;
}
Drag options to blanks, or click blank then click option'
Aprivate
Bconst
Cstatic
Dreadonly
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'const' inside interfaces is invalid.
Using 'static' or 'private' does not make properties readonly.
2fill in blank
medium

Complete 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'
Areadonly
Bprivate
Cpublic
Dstatic
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'private' instead of 'readonly'.
Forgetting to add any modifier.
3fill in blank
hard

Fix 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'
Areadonly
Bstatic
Cconst
Dprivate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'const' inside interfaces.
Using 'private' or 'static' incorrectly.
4fill in blank
hard

Fill 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'
Areadonly
Bprivate
Ctitle
Dstatic
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of keyword and property name.
Using 'private' or 'static' instead of 'readonly'.
5fill in blank
hard

Fill 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'
Areadonly
Bid
Cnumber
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' instead of 'number' for the type.
Omitting the readonly keyword.