nshanmugamram
8/15/2017 - 3:18 PM

type intersection and union


//Intersection and Union

type X = "start" | "end"
type Y = "end" | "old"
type Z = X & Y;//Intersection 
type L = X | Y;//Union

function someFunction1(some : L) {
    switch (some) {
        case "start": {
            console.log("start");
        }
        case "end": {
            console.log("start");
        }
        
        case "old": {
            console.log("start");
        }
    }
}
function someFunction(some : Z) {
    switch (some) {
        case "start": {
            console.log("start");
        }
        case "end": {
            console.log("start");
        }
        
        case "old": {
            console.log("start");
        }
    }
}
someFunction("end");
someFunction1("start");