0
0
Typescriptprogramming~10 mins

Creating type aliases in Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a type alias named Age for the number type.

Typescript
type Age = [1];
Drag options to blanks, or click blank then click option'
Anumber
Bstring
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of number.
Forgetting the semicolon at the end.
2fill in blank
medium

Complete the code to create a type alias named Coordinates for an object with x and y properties of type number.

Typescript
type Coordinates = [1];
Drag options to blanks, or click blank then click option'
A{ x: string; y: string }
B{ x: number; y: number }
C[number, number]
Dnumber[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using string types for x and y.
Using an array instead of an object.
3fill in blank
hard

Fix the error in the type alias declaration for Person which should have a name string and an optional age number.

Typescript
type Person = { name: string; age[1]: number };
Drag options to blanks, or click blank then click option'
A;
B:
C?
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using colon instead of question mark for optional property.
Missing the question mark causes age to be required.
4fill in blank
hard

Fill both blanks to create a type alias ID that can be either a string or a number.

Typescript
type ID = [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 string or number.
Forgetting the pipe symbol.
5fill in blank
hard

Fill all three blanks to create a type alias Response for an object with a status string, a data array of numbers, and an optional error string.

Typescript
type Response = { status: [1]; data: [2]; error[3]: string };
Drag options to blanks, or click blank then click option'
Astring
Bnumber[]
C?
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean instead of string for status.
Forgetting the question mark for the optional error property.