nshanmugamram
8/15/2017 - 3:10 PM

enforcing string with literals type


type Xtype = "start" | "end"
function createObj(x : Xtype) {
   
    switch (x) {
        case "start": {
            console.log("start");
            break;
        }

        case "end": {
            console.log("end");
             break;
        }
        default: {
            console.log("Not defined");
             break;
        }
         
    }
}
createObj("end")