I just started learning TypeScript, and I'm currently reading the handbook. One of the points it makes it that TypeScript catches logic errors, and it gives this example:
const value = Math.random() < 0.5 ? "a" : "b";
if (value !== "a") {
// ...
} else if (value === "b") {
// This condition will always return 'false' since
// the types '"a"' and '"b"' have no overlap.
// Oops, unreachable
}
Probably there's just something I'm not seeing straight, but I can't get why this should throw an error. Here's how I see it:
valuecan be eitheraorb- The first if statement checks to see if
valueisn'ta - The else-if statement checks if the value is
b, which it would always be if it wasn'ta(ifvalueis nota; it'sb)
So why does it say value === "b" will always return false? Obviously this doesn't work the way I'm looking at it; it seems like there's something I'm missing. Also I'm not totally sure what overlap in '"a"' and '"b"' have no overlap means, so if someone could help me understand these, it'd be greatly appreciated.