0
0
Typescriptprogramming~10 mins

Array type annotation 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 the shorthand syntax.

Typescript
let numbers: number[1] = [1, 2, 3];
Drag options to blanks, or click blank then click option'
A()
B{}
C[]
D<>
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces instead of square brackets.
Using angle brackets which are for generics, not array shorthand.
2fill in blank
medium

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

Typescript
let fruits: Array[1] = ['apple', 'banana', 'cherry'];
Drag options to blanks, or click blank then click option'
A{}
B<string>
C[]
D()
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of angle brackets.
Using square brackets which is shorthand, not generic syntax.
3fill in blank
hard

Fix the error in the array type annotation syntax.

Typescript
let scores: number[1] = [10, 20, 30];
Drag options to blanks, or click blank then click option'
A[]
B<>
C{}
D()
Attempts:
3 left
💡 Hint
Common Mistakes
Using angle brackets which are for generics, not shorthand arrays.
Using parentheses or curly braces which are invalid here.
4fill in blank
hard

Fill both blanks to declare an array of booleans using generic syntax.

Typescript
let flags: Array[1] = [2];
Drag options to blanks, or click blank then click option'
A<boolean>
B[true, false, true]
C[false, true]
D<string>
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong type inside angle brackets.
Using a string array instead of boolean array.
5fill in blank
hard

Fill all three blanks to declare an array of objects with a specific type.

Typescript
type Person = { name: string, age: number };
let people: [1] = [2];

people.push([3]);
Drag options to blanks, or click blank then click option'
AArray<Person>
B[{ name: 'Alice', age: 30 }]
C{ name: 'Bob', age: 25 }
DPerson[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using shorthand array syntax instead of generic syntax for the type.
Pushing a non-object or missing required properties.