If you use TypeScript, you can use the actual enumeration . Then you can check it using in :
export enum MESSAGE_TYPE { INFO = 1, SUCCESS = 2, WARNING = 3, ERROR = 4, }; var type = 3; if (type in MESSAGE_TYPE) { }
This works because when you compile the above listing, it generates the following object:
{ '1': 'INFO', '2': 'SUCCESS', '3': 'WARNING', '4': 'ERROR', INFO: 1, SUCCESS: 2, WARNING: 3, ERROR: 4 }
source share