Dev Helpers
← Back

Implement an abstract method

Implement an abstract method using TypeScript.

Open this example in the interactive library

Source code

interface Named {
  name: string;
}
console.log(
  (() => {
    abstract class Shape {
      abstract area(): number;
    }
    class Square extends Shape {
      area() {
        return 4;
      }
    }
    return new Square().area();
  })(),
);

Sample output

4