Course contentsShow
← TypeScript
Lesson 1044 of 1,79624. Classes in TypeScriptFree lesson

The implements Keyword

How classes can declare they fulfill an interface contract and what the compiler checks.

The implements Keyword

What you'll learn: How classes can declare they fulfill an interface contract and what the compiler checks when you use implements.

What Is implements?

The implements keyword lets you declare that a class promises to satisfy the structure defined by an interface. Think of it as a blueprint approval process: the interface describes what properties and methods must exist, and the compiler verifies your class actually provides them.

Unlike inheritance (extends), which copies behavior from a parent class, implements only enforces a shape check. The interface doesn't provide any implementation—your class must write all the code itself.

How It Works

When you write class MyClass implements MyInterface, TypeScript checks:

  • Every property in the interface exists in the class
  • Property types match exactly
  • Method signatures match (parameters and return types)

If anything is missing or mismatched, you get a compile-time error—before any code runs.

interface Connectable {
  host: string;
  port: number;
  connect(): void;
}

class Database implements Connectable {
  host: string;
  port: number;

  constructor(host: string, port: number) {
    this.host = host;
    this.port = port;
  }

  connect(): void {
    console.log(`Connecting to ${this.host}:${this.port}`);
  }
}

The compiler verifies that Database has host, port, and connect() with the correct types. If you forget port or make connect() return a string, TypeScript will error.

Key Takeaway: The implements keyword enforces that your class adheres to an interface contract, giving you compile-time guarantees about structure without inheriting any behavior.