0
0
Typescriptprogramming~10 mins

Why type aliases are needed in Typescript - Test Your Understanding

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'
Aboolean
Bstring
Cnumber
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using a value like 5 instead of a type like number.
Confusing type aliases with variables.
2fill in blank
medium

Complete the code to define a type alias Point for an object with x and y as numbers.

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

Fix the error by completing the type alias for a union of string literals representing directions.

Typescript
type Direction = [1];
Drag options to blanks, or click blank then click option'
Aup | down | left | right
B"up" | "down" | "left" | "right"
Cstring
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out quotes around string literals.
Using variable names instead of string literals.
4fill in blank
hard

Fill all three blanks to create a type alias Response that can be either a string or a number.

Typescript
type Response = [1] [2] [3];
Drag options to blanks, or click blank then click option'
Astring
B|
Cnumber
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using & instead of | for union.
Forgetting to separate types with |.
5fill in blank
hard

Fill all three blanks to create a type alias User for an object with id as number, name as string, and an optional age as number.

Typescript
type User = { id: [1]; name: [2]; age?: [3]; };
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong types for properties.
Forgetting the optional marker ?.