Intersection Types

suggest change

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();
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents