TypeScript/tests/cases/compiler/matchReturnTypeInAllBranches.ts
2014-07-12 17:30:19 -07:00

35 lines
1.2 KiB
TypeScript

// Represents a monster who enjoys ice cream
class IceCreamMonster {
private iceCreamFlavor: string;
private iceCreamRemaining: number;
private wantsSprinkles: boolean;
private soundsWhenEating: string;
public name: string;
constructor(iceCreamFlavor: string, wantsSprinkles: boolean, soundsWhenEating: string, name: string) {
this.iceCreamFlavor = iceCreamFlavor;
this.iceCreamRemaining = 100;
this.wantsSprinkles = wantsSprinkles;
this.soundsWhenEating = soundsWhenEating;
this.name = name;
}
/**
* Tells the IceCreamMonster to eat their ice cre am!
*
* @param {number} amount The amount of ice cream to e at.
* @return {boolean} True if ice cream remains, false if there is no more ice cream le ft.
*/
public eatIceCream(amount: number): boolean {
this.iceCreamRemaining -= amount;
if (this.iceCreamRemaining <= 0)
{
this.iceCreamRemaining = 0;
return false;
}
else
{
return 12345;
}
}
}
var cookieMonster: IceCreamMonster;
cookieMonster = new IceCreamMonster("Chocolate Chip", false, "COOOOOKIE", "Cookie Monster");