0
0
Typescriptprogramming~10 mins

Rest elements in tuples 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 tuple with a rest element that collects numbers.

Typescript
type Numbers = [string, ...[1][]];
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' instead of 'number' for the rest element.
Forgetting the spread operator '...'.
2fill in blank
medium

Complete the code to define a tuple type where the first element is a boolean and the rest are strings.

Typescript
type BoolStrings = [[1], ...string[]];
Drag options to blanks, or click blank then click option'
Aboolean
Bstring
Cnumber
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'number' instead of 'boolean' for the first element.
Placing the rest element before the first element.
3fill in blank
hard

Fix the error in the tuple type that tries to use multiple rest elements.

Typescript
type InvalidTuple = [number, ...string[]];
Drag options to blanks, or click blank then click option'
Aboolean
Bnumber
Cstring
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to add multiple rest elements in a tuple.
Placing the rest element in the middle of the tuple.
4fill in blank
hard

Fill both blanks to create a tuple type with a string first element and a rest element collecting booleans.

Typescript
type TupleWithRest = [[1], ...[2][]];
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the types for the first element and rest element.
Using 'number' instead of 'boolean' for the rest element.
5fill in blank
hard

Fill all three blanks to define a tuple type with a number first element, a boolean second element, and a rest element collecting strings.

Typescript
type ComplexTuple = [[1], [3], ...[2][]];
Drag options to blanks, or click blank then click option'
Anumber
Bstring
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Placing the rest element after the last element.
Using wrong types for the positions.