Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 414 Bytes

File metadata and controls

26 lines (20 loc) · 414 Bytes

Section 3.4: Intersection Types

A Intersection Type combines the member of two or more types.

interface Knife {
  cut();
}

interface BottleOpener{
  openBottle();
}

interface Screwdriver{
  turnScrew();
}

type SwissArmyKnife = Knife & BottleOpener & Screwdriver;

function use(tool: SwissArmyKnife){
  console.log("I can do anything!");
  tool.cut();
  tool.openBottle();
  tool.turnScrew();
}