Codectionary / Developer documentation / TypeScript

implements Keyword

The implements keyword declares that a class must conform to a specific interface's shape - TypeScript checks that every property and method the interface requires is actually present with a compatible type. Unlike extends, implements does not provide any inherited implementation; it is purely a compile-time contract check.

Syntax

class Name implements InterfaceName { }

Examples

Enforcing a Contract

A class guaranteed to match an interface's shape.

interface Printable {
  print(): void;
}

interface Serializable {
  serialize(): string;
}

class Document implements Printable, Serializable {
  constructor(private content: string) {}

  print(): void {
    console.log(this.content);
  }

  serialize(): string {
    return JSON.stringify({ content: this.content });
  }
}
// If Document were missing either method, TypeScript would flag it immediately

Best practices

  • Use implements to guarantee a class provides all the members a given interface requires, catching missing implementations at compile time
  • A class can implement multiple interfaces at once, comma-separated - useful for composing several small, focused contracts
  • Remember implements provides no code - it is purely a type-level check; use extends when you actually want to inherit real behavior
  • Combine implements with an interface exported from a shared location when multiple classes across a codebase need to honor the same contract

At a glance

Purpose
Static types for JavaScript
File extension
.ts ยท .tsx
Runs in
Compiled to JavaScript
Usually used with
JavaScript and its ecosystem

Specifications & further reading

Related TypeScript documentation