0
0
Typescriptprogramming~10 mins

Tuple type definition 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 define a tuple type with a string and a number.

Typescript
let user: [1] = ['Alice', 30];
Drag options to blanks, or click blank then click option'
AArray<number>
B[string, number]
Cstring[]
Dobject
Attempts:
3 left
💡 Hint
Common Mistakes
Using string[] which allows any number of strings, not a fixed tuple.
Using Array which is an array of numbers only.
2fill in blank
medium

Complete the code to define a tuple type with a boolean and a string.

Typescript
const flag: [1] = [true, 'active'];
Drag options to blanks, or click blank then click option'
A[string, boolean]
BArray<string>
Cboolean[]
D[boolean, string]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of types in the tuple.
Using boolean[] which allows any number of booleans.
3fill in blank
hard

Fix the error in the tuple type definition to match the assigned value.

Typescript
let data: [1] = [42, 'answer'];
Drag options to blanks, or click blank then click option'
A[number, string]
B[string, number]
C[number, number]
D[string, string]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the types in the tuple definition.
Using the wrong types that don't match the assigned values.
4fill in blank
hard

Fill both blanks to define a tuple type with a number and a boolean, and assign a matching value.

Typescript
const pair: [1] = [[2], false];
Drag options to blanks, or click blank then click option'
A[number, boolean]
Btrue
C42
D[boolean, number]
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong order of types in the tuple.
Assigning a value that does not match the tuple type.
5fill in blank
hard

Fill all three blanks to define a tuple type with a string, number, and boolean, and assign a matching value.

Typescript
let info: [1] = [[2], [3], true];
Drag options to blanks, or click blank then click option'
A[string, number, boolean]
B'hello'
C100
D[number, string, boolean]
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of types in the tuple.
Using values that don't match the tuple types.