I'm trying to learn TypeScript and had been following online tutorial examples for enum support in TypeScript. For this below snippet:
enum daysoftheweek{
SUN, MON, TUE, WED, THU, FRI, SAT
}
let day:daysoftheweek ;
day = daysoftheweek.FRI; //line 7
if (day === daysoftheweek.MON){
console.log("got to go to work early");
}else{
console.log("I may go late");
}
...I'm getting this error at compile time and I don't understand why:
TS2367: This condition will always return 'false' since the types 'daysoftheweek.FRI' and 'daysoftheweek.MON' have no overlap.
If I modify line 7 to this, the error goes off:
day = daysoftheweek.MON;
Can somebody please explain why compilation is throwing that error?
(I followed other threads on this "have no overlap" error , but couldn't understand the reason for this particular snippet's problem)
There is no logic applied that could affect the value of the day variable -- the complier can plainly see that it will always be daysoftheweek.FRI. The error is telling you that it will never equal daysoftheweek.MON so the if statement has no purpose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With