A typing mistake, I meant the union types for for primitive types (at least for primitive types, ideally for any type).
Exhaustive Type Checking. Compile type checking for correct usage of union
types in if/switch/return statements and functions.
function makeDessert( fruit: 'banana' | 'orange' ): string {
switch( fruit ) {
case 'banana': return 'Banana Shake'
case 'orange': return 'Orange Juice'
}
return fruit // Compiler will spot this as unreachable code.
}
Run
