#enum used as key to map should not have possible undefined

3 messages · Page 1 of 1 (latest)

dusty hornet
#

im passing in an enum to companyNameCountryVariantMap country2Code: CountryVariants

export const companyNameCountryVariantMap = new Map<keyof typeof CountryVariants, string>([
  [CountryVariants.UK, 'Company Name'],
  [CountryVariants.LU, 'Registered Name'],
  [CountryVariants.US, 'Company Name'],
]);
proper python
#

Map doesn't guarantee exhaustiveness. new Map<CountryVariants, string> just means that the map has CountryVariants keys and string values
it's a mapping between values but it isn't an exhaustive mapping over the enum

#

you may want to use a record rather than a map; a record with a union literal key specifies exhaustive mapping