Using the 1.5kB library Superenum this is easy:
import { Enum, EnumType } from '@ncoderz/superenum'
export const MESSAGE_TYPE = {
INFO: 1,
SUCCESS: 2,
WARNING: 3,
ERROR: 4,
};
const validatedValue = Enum(MESSAGE_TYPE).fromValue(3); // 3
const badValue = Enum(MESSAGE_TYPE).fromValue(7); // undefined