Have you heard about Hack Frontend Community?Join us on Telegram!
Practice TS Problems

implements in TypeScript: Enforcing Interface Contracts

In TypeScript, the implements keyword is used to force a class to conform to an interface.

This means the class must implement all properties and methods described in the interface. Otherwise TypeScript will throw a compilation error.

Syntax

interface IAnimal {
  name: string;
  makeSound(): void;
}

class Dog implements IAnimal {
  name: string;

  constructor(name: string) {
    this.name = name;
  }

  makeSound() {
    console.log("Woof!");
  }
}

What happens?

  • Class Dog must implement all properties and methods of interface IAnimal.
  • If at least one is missing — TypeScript will show an error.

Error Example

interface Person {
  name: string;
  age: number;
}

class User implements Person {
  name: string;
  // Error: Property 'age' is missing
}

implements with multiple interfaces

Can implement multiple interfaces separated by commas:

interface A {
  a(): void;
}

interface B {
  b(): void;
}

class C implements A, B {
  a() {
    console.log("A");
  }

  b() {
    console.log("B");
  }
}

Why use implements?

  • For structure control of class
  • For API documentation: it's clear what class should support
  • For architectural compliance guarantees
  • For modularity and reusability: one interface — many implementations

Important:

implements works only at type level. In compiled JavaScript there are no interfaces.

Practice TS Problems

By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.