100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
TypeScript

Abstract Classes in TypeScript

Define shared structure and behavior for a family of subclasses using abstract classes and abstract methods that must be implemented by derived classes.

Classes & OOPIntermediate8 min readJul 8, 2026
Analogies

1. Introduction

An abstract class is a class that cannot be instantiated directly — it exists purely to be extended. It can define fully-implemented methods shared by all subclasses, as well as abstract methods that declare a signature without a body, forcing every concrete subclass to provide its own implementation.

🏏

Cricket analogy: You can't select 'Bowler' as a player on the team sheet — only concrete bowlers like Jasprit Bumrah or Mitchell Starc, each supplying their own run-up, while the shared 'walk back to mark' routine stays identical for all.

2. Syntax

typescript
abstract class BaseClassName {
  abstract methodName(): ReturnType; // no body

  concreteMethod(): void {
    // shared implementation
  }
}

class DerivedClassName extends BaseClassName {
  methodName(): ReturnType {
    // required implementation
  }
}

3. Explanation

The abstract keyword before class marks the class as abstract, and abstract before a method declares that method's signature without providing a body. TypeScript enforces two rules: you can never write new BaseClassName() directly, and any non-abstract subclass must implement every abstract method inherited from its base class.

🏏

Cricket analogy: Just as you can never write 'select Generic Bowler' on a scorecard, TypeScript blocks new Bowler() on an abstract class — every specific bowler like Bumrah must supply the run-up method the base class only declared.

Abstract classes are useful when several related classes share common behavior (like a describe() method) but each needs its own specialized logic for a specific operation (like calculating an area). This is a form of polymorphism: code that works with the abstract base type can call the shared method, and the correct subclass implementation runs automatically.

🏏

Cricket analogy: All-rounders share a common 'walk to the crease' routine but each has specialized batting technique — call bat() on any all-rounder like Hardik Pandya or Ben Stokes and their own specific shot execution runs automatically.

Abstract classes cannot be instantiated directly — writing new Shape() where Shape is declared abstract class Shape produces the compile-time error: "Cannot create an instance of an abstract class." You must extend the abstract class and instantiate a concrete subclass instead.

4. Example

typescript
abstract class Shape {
  abstract area(): number;

  describe(): string {
    return `Area is ${this.area()}`;
  }
}

class Circle extends Shape {
  constructor(private radius: number) {
    super();
  }

  area(): number {
    return Math.PI * this.radius ** 2;
  }
}

class Square extends Shape {
  constructor(private side: number) {
    super();
  }

  area(): number {
    return this.side * this.side;
  }
}

const shapes: Shape[] = [new Circle(2), new Square(4)];
shapes.forEach((s) => console.log(s.describe()));

// const s = new Shape();
// Error: Cannot create an instance of an abstract class.

5. Output

text
Area is 12.566370614359172
Area is 16

6. Key Takeaways

  • An abstract class can never be instantiated directly with 'new'.
  • Abstract methods declare a signature with no body and must be implemented by every concrete subclass.
  • Abstract classes can mix abstract methods with fully implemented (concrete) methods.
  • Subclasses use 'extends' and must call super() before accessing 'this' in their constructor.
  • Abstract classes enable polymorphism: shared base-class logic can call subclass-specific implementations.

Practice what you learned

Was this page helpful?

Topics covered

#TypeScript#TypeScriptProgrammingStudyNotes#Programming#AbstractClassesInTypeScript#Abstract#Classes#Syntax#Explanation#OOP#StudyNotes#SkillVeris