RecipesChapter 11: Classes

Deciding When to Use Classes or Namespaces

Recipe 11.6 from The TypeScript Cookbook

interface Lifeform {
  move(): string;
}

class BasicLifeForm {
  age: number;
  constructor(age: number) {
    this.age = age;
  }
}

class Human extends BasicLifeForm implements Lifeform {
  move() {
    return "Walking";
  }
}
Open in TypeScript Playground →