Let's say I am receiving data from my backend which can be one of the following:
A,
B,
C,
D
Although there are actually 20 letters that could be received, and I always know it will be one of these specific letters. For example, I would like to map A
to display as Alfa
, and B
should display as Beta
. Is there a more efficient way to do this without creating a large switch statement?
I attempted using a constant like this:
export const Test = {
SWE: 'Sweden',
DK: 'Denmark'
}
And then trying to access it using:
Test[countrycode]
However, this causes an error stating
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ SWE: string; DK: string;
The reason quotes are missing around the keys is due to prettier formatting requirements.