Here is a function that maps a place to an emoji:
function mapPlaceToEmoji(place: Place): string {
switch (place) {
case Place.FIRST:
return '🥇';
case Place.SECOND:
return '🥈';
case Place.THIRD:
return '🥉';
}
}
It works perfectly fine with a regular enum:
enum Place {
FIRST,
SECOND,
THIRD,
}
But when using an ambient enum, it doesn't work:
declare enum Place {
FIRST,
SECOND,
THIRD,
}
This results in the following error:
Function lacks ending return statement and return type does not include 'undefined'.(2366)
Is there a way to use an exhaustive switch statement with ambient enum types?