0
0
Typescriptprogramming~10 mins

Generic interface declaration 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 generic interface named Container with a type parameter T.

Typescript
interface Container<[1]> {
  value: T;
}
Drag options to blanks, or click blank then click option'
AT
BU
CV
DK
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase letters for generic type parameters.
Forgetting the angle brackets <> around the generic parameter.
2fill in blank
medium

Complete the code to declare a generic interface Pair with two type parameters T and U.

Typescript
interface Pair<[1], U> {
  first: T;
  second: U;
}
Drag options to blanks, or click blank then click option'
AV
BS
CK
DT
Attempts:
3 left
💡 Hint
Common Mistakes
Using a type parameter that is not referenced in the interface.
Swapping the order of type parameters.
3fill in blank
hard

Fix the error in the generic interface declaration by completing the code.

Typescript
interface Result<[1]> {
  data: T[];
  error?: string;
}
Drag options to blanks, or click blank then click option'
AT
BU
CV
DE
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different letter for the generic parameter than the one used inside the interface.
Omitting the generic parameter entirely.
4fill in blank
hard

Fill both blanks to declare a generic interface Dictionary with key type K and value type V.

Typescript
interface Dictionary<[1], [2]> {
  [key: K]: V;
}
Drag options to blanks, or click blank then click option'
AK
BT
CV
DU
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of K and V.
Using type parameters not referenced in the interface.
5fill in blank
hard

Fill all three blanks to declare a generic interface Triple with types A, B, and C for its properties.

Typescript
interface Triple<[1], [2], [3]> {
  first: A;
  second: B;
  third: C;
}
Drag options to blanks, or click blank then click option'
AA
BB
CC
DT
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same letter for multiple generic parameters.
Not matching the generic parameters with the property types.