Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hasparus
Created August 4, 2019 13:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasparus/76b2948f69d817049ffd4e744975a422 to your computer and use it in GitHub Desktop.
Save hasparus/76b2948f69d817049ffd4e744975a422 to your computer and use it in GitHub Desktop.
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'.
}