0
0
Typescriptprogramming~15 mins

Multiple interface extension in Typescript - Mini Project: Build & Apply

Choose your learning style9 modes available
Multiple Interface Extension in TypeScript
📖 Scenario: Imagine you are creating a simple system to describe different types of vehicles. Each vehicle has some common features, but some vehicles have extra features. You want to use TypeScript interfaces to organize these features clearly.
🎯 Goal: You will build TypeScript interfaces where one interface extends multiple other interfaces. This helps combine features from different sources into one interface.
📋 What You'll Learn
Create interfaces with specific properties
Use multiple interface extension
Create an object that uses the extended interface
Print the combined object properties
💡 Why This Matters
🌍 Real World
Using multiple interface extension helps organize complex data models in software, like describing vehicles with many features.
💼 Career
Understanding interface extension is important for TypeScript developers to write clean, reusable, and scalable code.
Progress0 / 4 steps
1
Create base interfaces
Create two interfaces called Engine and Wheels. The Engine interface should have a property horsepower of type number. The Wheels interface should have a property count of type number.
Typescript
Need a hint?

Use the interface keyword to create interfaces. Each property needs a name and a type.

2
Create an interface that extends both Engine and Wheels
Create an interface called Car that extends both Engine and Wheels. Add a new property brand of type string to Car.
Typescript
Need a hint?

Use extends with a comma to extend multiple interfaces.

3
Create a variable of type Car
Create a variable called myCar of type Car. Assign it an object with horsepower 150, count 4, and brand "Toyota".
Typescript
Need a hint?

Use const to create the variable and assign an object with all required properties.

4
Print the car details
Write a console.log statement to print the string: "My Toyota car has 150 horsepower and 4 wheels." using the properties of myCar.
Typescript
Need a hint?

Use a template string with backticks and ${} to insert variables inside the string.