Within a nest.js service, there is a service method that takes an error code and generates a corresponding message to display to the user. The example below shows a simplified version of this method:
getGenericErrorMessage(input: string): string {
const errorMessages = {
unknownError: 'An unknown error occurred.',
noResponse: 'The Application did not send a response.',
};
return errorMessages[input] || errorMessages['unknownError'];
}
Is there a way to enable intellisense for valid function parameters that are defined as keys in the errorMessages
object? Alternatively, what is the best approach to restructure the code to achieve this functionality?