Challenge: TypeScript Inheritance

Complete the challenge of implementing inheritance in TypeScript.

In this challenge, you are required to implement a class hierarchy for a shape-based application. The application needs to handle various shapes such as circles, squares, and triangles. Each shape has specific properties and behavior. Your goal is to create TypeScript classes that represent these shapes and their interactions.

Requirements

Here are the simplified requirements for this challenge:

  1. Create an abstract Shape class with the following properties and methods.

    1. Properties: name: string (the name of the shape)

    2. Methods: abstract calculateArea(): number (calculates the area of the shape)

  2. Implement a Circle class that extends Shape with the following properties and methods:

    1. Properties: radius: number

    2. Methods: calculateArea(): number (calculates the area of the circle)

  3. Implement a Square class that extends Shape with the following properties and methods:

    1. Properties: sideLength: number

    2. Methods: calculateArea(): number (calculates the area of the square)

  4. Implement a Triangle class that extends Shape with the following properties and methods:

    1. Properties: base: number and height: number

    2. Methods: calculateArea(): number (calculates the area of the triangle)

Example input and output

The following are the example inputs and outputs:

Get hands-on with 1400+ tech skills courses.