100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
TypeScript

Implementing Interfaces in TypeScript

Use the implements keyword to make a class satisfy an interface's compile-time contract, and understand how this differs from extending a base class.

Classes & OOPIntermediate7 min readJul 8, 2026
Analogies

1. Introduction

An interface describes the shape a value must have — the properties and methods it must expose — without providing any implementation. A class can promise to satisfy one or more interfaces using the implements keyword, and the compiler checks that the class actually provides every member the interface requires.

🏏

Cricket analogy: A team's selection criteria sheet lists required skills like bowling at 140kph and fielding at slip without specifying how a player developed them, and selectors check each recruit meets every listed requirement.

2. Syntax

typescript
interface InterfaceName {
  propertyName: Type;
  methodName(): ReturnType;
}

class ClassName implements InterfaceName {
  propertyName: Type;

  methodName(): ReturnType {
    // must be implemented
  }
}

// A class can implement multiple interfaces:
class Other implements InterfaceA, InterfaceB { /* ... */ }

3. Explanation

implements is a compile-time-only contract check: the interface itself produces no JavaScript code and is completely erased after compilation. A class can implement multiple interfaces at once, separated by commas, which is not possible with extending a base class (TypeScript classes only support single inheritance via extends).

🏏

Cricket analogy: A player's all-rounder badge on the team sheet exists only for pre-match review and vanishes once play starts, and one player can be certified both a batting all-rounder and a fielding specialist at once, unlike inheriting a single mentor's exact technique.

This is the key distinction between implements and extends: extends inherits actual implementation (fields, method bodies, and behavior) from a single base class, while implements only enforces that the class's own code independently satisfies each interface member's type signature — nothing is inherited from the interface.

🏏

Cricket analogy: extends is like a young batter training directly under one senior mentor and inheriting his actual batting stance, while implements is like meeting a selector's checklist of required skills the player must independently develop.

A class implements an interface (a compile-time shape check, and you can implement several interfaces at once) versus extends a class (inherits real implementation, and TypeScript only allows extending one base class). A class can also do both at the same time: class Foo extends Base implements InterfaceA, InterfaceB.

4. Example

typescript
interface Flyable {
  maxAltitude: number;
  fly(): string;
}

interface Swimmable {
  swim(): string;
}

class Duck implements Flyable, Swimmable {
  maxAltitude = 300;

  fly(): string {
    return `Flying up to ${this.maxAltitude}m`;
  }

  swim(): string {
    return "Paddling across the pond";
  }
}

const duck = new Duck();
console.log(duck.fly());
console.log(duck.swim());

5. Output

text
Flying up to 300m
Paddling across the pond

6. Key Takeaways

  • implements checks that a class provides every property/method an interface requires.
  • A class can implement multiple interfaces at once, unlike extending only one base class.
  • Interfaces produce no runtime JavaScript code; the check is compile-time only.
  • implements does not inherit implementation, only enforces a type shape.
  • A class can both extend a base class and implement one or more interfaces simultaneously.

Practice what you learned

Was this page helpful?

Topics covered

#TypeScript#TypeScriptProgrammingStudyNotes#Programming#ImplementingInterfacesInTypeScript#Implementing#Interfaces#Syntax#Explanation#StudyNotes#SkillVeris