Skip to main content
Practice Problems

What does implements do in TypeScript?

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

ts
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

ts
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:

ts
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.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Finished reading?
Practice Problems