0
0
Typescriptprogramming~10 mins

Type alias for objects 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 Person for an object with a name string property.

Typescript
type Person = [1];
Drag options to blanks, or click blank then click option'
A{ name: string }
B[name: string]
C(name: string)
D<name: string>
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or parentheses instead of curly braces.
Forgetting the colon between property name and type.
2fill in blank
medium

Complete the code to define a type alias Car with make and year properties.

Typescript
type Car = { make: string; [1]: number };
Drag options to blanks, or click blank then click option'
Amodel
Byear
Ccolor
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong property name like model or color.
Using a string type instead of number for the year.
3fill in blank
hard

Fix the error in the type alias by completing the code correctly.

Typescript
type Book = [1] title: string; author: string };
Drag options to blanks, or click blank then click option'
A[
B(
C{
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or parentheses instead of curly braces.
Missing the opening brace causes syntax errors.
4fill in blank
hard

Fill both blanks to define a type alias Employee with id as a number and name as a string.

Typescript
type Employee = { [1]: number; [2]: string };
Drag options to blanks, or click blank then click option'
Aid
Bage
Cname
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names like age or salary.
Swapping the types of the properties.
5fill in blank
hard

Fill all three blanks to define a type alias Product with id (number), name (string), and inStock (boolean).

Typescript
type Product = { [1]: number; [2]: string; [3]: boolean };
Drag options to blanks, or click blank then click option'
AinStock
Bname
Cid
Davailable
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names like available instead of inStock.
Mixing up the order of properties.