0
0
Typescriptprogramming~10 mins

Generic array syntax 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 an array of numbers using generic syntax.

Typescript
let numbers: Array<[1]> = [1, 2, 3];
Drag options to blanks, or click blank then click option'
Astring
Bboolean
Cany
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'boolean' instead of 'number' for the array type.
2fill in blank
medium

Complete the code to declare an array of strings using generic syntax.

Typescript
const fruits: Array<[1]> = ['apple', 'banana', 'cherry'];
Drag options to blanks, or click blank then click option'
Astring
Bobject
Cboolean
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'number' or 'object' instead of 'string' for the array type.
3fill in blank
hard

Fix the error in the generic array declaration.

Typescript
let flags: Array[1] = [true, false, true];
Drag options to blanks, or click blank then click option'
A[boolean]
B<boolean>
C(boolean)
D{boolean}
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or parentheses instead of angle brackets.
4fill in blank
hard

Fill both blanks to declare an array of objects with a generic type.

Typescript
const users: Array<[1]> = [[2]];
Drag options to blanks, or click blank then click option'
A{ name: string; age: number }
B{ name: 'Alice', age: 30 }
C{ name: 'Bob', age: 25 }
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string type instead of an object type for the generic.
Putting the object type inside the array instead of an object instance.
5fill in blank
hard

Fill all three blanks to declare and initialize a generic array of booleans.

Typescript
let flags: Array<[1]> = [[2], [3]];
Drag options to blanks, or click blank then click option'
Aboolean
Btrue
Cfalse
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' as the generic type.
Using non-boolean values inside the array.