Created
August 4, 2019 13:20
-
-
Save hasparus/76b2948f69d817049ffd4e744975a422 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function exhaustive(x: never): never { | |
throw new Error(` | |
Unreachable default case. | |
${x} is not assignable to type never. | |
`) | |
} | |
type Fruit = "apple" | "banana" | "mango"; | |
declare const fruit: Fruit; | |
switch (fruit) { | |
case 'apple': | |
break; | |
case 'banana': | |
break; | |
default: exhaustive(fruit); // Argument of type '"mango"' is not assignable to parameter of type 'never'. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABAUwB4AsCGIDOsBuyAFKgFyJjKEBOAlOZTYgN4BQiiU61cA7hcn4BRaj2pEABuw6IAqmGrJMELACMANskQATZMGzqoiCJhzIAdNI4ASZqgC+iGDgpwjpnDADmYTBq1QcJwAngAOWozI1JYcErSs9qysUGFaAGLUIDBGALyIAESYoaGa+YgAPgWqmL6+ZZX5ALY1XnD5ANxJuhDqmIrGCHiIwJnZ5BlZUJ2sOLzZKohEI5O0LNImZogA5EUlyFukVoiqipgA1p0cG1pb1bWYB0cnShfSuvoghuRoWLgExMtsrROvYgA