0
0
Typescriptprogramming~10 mins

Type alias for unions 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 type alias named Result that can be either a string or a number.

Typescript
type Result = [1];
Drag options to blanks, or click blank then click option'
Astring & number
Bstring, number
Cstring number
Dstring | number
Attempts:
3 left
💡 Hint
Common Mistakes
Using & instead of | which means intersection, not union.
Separating types with a comma instead of |.
2fill in blank
medium

Complete the code to define a type alias Status that can be either 'success' or 'error'.

Typescript
type Status = [1];
Drag options to blanks, or click blank then click option'
A'success' 'error'
B'success' | 'error'
C'success', 'error'
D'success' & 'error'
Attempts:
3 left
💡 Hint
Common Mistakes
Using & which means intersection and is not valid for string literals here.
Separating with commas or spaces instead of |.
3fill in blank
hard

Fix the error in the type alias Input so it correctly represents a union of boolean or number.

Typescript
type Input = boolean [1] number;
Drag options to blanks, or click blank then click option'
A|
B&
C,
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using & which means intersection, not union.
Using commas or slashes which are invalid here.
4fill in blank
hard

Fill both blanks to define a type alias Response that can be either a string or an array of numbers.

Typescript
type Response = [1] | [2];
Drag options to blanks, or click blank then click option'
Astring
Bnumber[]
Cboolean
Dobject
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean or object instead of the correct types.
Forgetting the union operator |.
5fill in blank
hard

Fill all three blanks to define a type alias Data that can be a string, number, or an array of booleans.

Typescript
type Data = [1] | [2] | [3];
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cboolean[]
Dobject
Attempts:
3 left
💡 Hint
Common Mistakes
Including object which is not part of the union.
Using intersection & instead of union |.