Functions - Overloading
function cook(ingredients:IngredientList, crockpot:Crockpot, temp:number, time:number): CrockpotMeal;
function cook(ingredients:IngredientList, skillet:Skillet): SkilletMeal;
function cook(ingredients:IngredientList, cookingAppliance:any, ...options:Array): Meal {
if (typeof cookingAppliance === "Skillet") {
return new SkilletMeal(ingredients);
} else if (typeof cookingAppliance === "Crockpot") {
return new CrockpotMeal(ingredients, options[0], options[1]);
}
}
let skillet = cook(new IngredientList(), new Skillet());
let crockpost = cook(new IngredientList(), new Crockpot(), 225, 360);
let dutchoven = cook(new DutchOven());
> $ tsc examples/functions/overload.ts
examples/functions/overload.ts(19,17): error TS2346: Supplied parameters do not match any signature
of call target.