Edit
https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#literal-types-are-inferred-by-default-for-const-variables-and-readonly-properties
This is the list of breaking changes per version, linked to what I think is the change you're looking for. In summary:
String, numeric, boolean and enum literal types are not inferred by default for const declarations and readonly properties. This means your variables/properties an have more narrowed type than before. This could manifest in using comparison operators such as === and !==.
const DEBUG = true; // Now has type `true`, previously had type `boolean`
if (DEBUG === false) { /// Error: operator '===' can not be applied to 'true' and 'false'
...
}
So don't forget to declare you types, it is typescript after all. If you change temp to temp: number like so:
function enumDemo() {
enum temperature{
cold,
hot
};
let temp: number = temperature.cold;
switch (temp) {
case temperature.cold:
console.log("Brrr...");
break;
case temperature.hot:
console.log("yikes!");
break;
}
}
It should work fine. What's happening is the compiler is trying to assign the enum type, rather than the number the enum represents.
And alternative method would be to make a class with static members instead of an enum
export class temperature {
public static cold: number = 0;
public static hot: number = 1;
}