Created
February 11, 2024 10:30
-
-
Save turbod/2e4d51653e99469f0dcf0a5c2c589b52 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
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