Skip to content

Instantly share code, notes, and snippets.

@turbod
Created February 11, 2024 10:30
Show Gist options
  • Save turbod/2e4d51653e99469f0dcf0a5c2c589b52 to your computer and use it in GitHub Desktop.
Save turbod/2e4d51653e99469f0dcf0a5c2c589b52 to your computer and use it in GitHub Desktop.
type Locations = 'Zurich' | 'Warsaw' | 'London';
function getCountryLocation(location: Locations) {
switch (location) {
case 'Zurich':
return 'Switzerland';
case 'Warsaw':
return 'Poland';
case 'London':
return 'UK';
default:
// const _exhaustiveCheck: never = location;
throw new Error(`Invalid ${location satisfies never}`);
}
}
getCountryLocation('Zurich');
getCountryLocation('Paris');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment