0
0
Typescriptprogramming~10 mins

Optional 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 an optional second element.

Typescript
let tuple: [number, string[1]];
Drag options to blanks, or click blank then click option'
A?
B!
C:
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Using a colon or semicolon instead of a question mark.
Forgetting to mark the element as optional.
2fill in blank
medium

Complete the code to create a tuple type where the last element is optional and of type boolean.

Typescript
type MyTuple = [string, number, boolean[1]];
Drag options to blanks, or click blank then click option'
A?
B!
C:
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Using exclamation mark or colon instead of question mark.
Placing the question mark before the type.
3fill in blank
hard

Fix the error in the tuple type declaration to make the second element optional.

Typescript
let data: [string, number[1]];
Drag options to blanks, or click blank then click option'
A;
B!
C:
D?
Attempts:
3 left
💡 Hint
Common Mistakes
Using exclamation mark or colon instead of question mark.
Not placing the question mark immediately after the type.
4fill in blank
hard

Fill both blanks to declare a tuple with an optional second element of type string and an optional third element of type boolean.

Typescript
let tuple: [number, string[1], boolean[2]];
Drag options to blanks, or click blank then click option'
A?
B!
C:
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Using exclamation marks or colons instead of question marks.
Marking only one element as optional.
5fill in blank
hard

Fill both blanks to create a tuple type with an optional first element of type string, a required second element of type number, and an optional third element of type boolean.

Typescript
type CustomTuple = [string[1], number, boolean[2]];
Drag options to blanks, or click blank then click option'
A?
D!
Attempts:
3 left
💡 Hint
Common Mistakes
Marking the required element as optional.
Using exclamation marks instead of question marks.