Is it possible to convert enum that looks for exmp:
enum StatusCodeEnum {
OK = 200,
BAD_REQUEST = 400,
UNAUTHORIZED = 401,
FORBIDDEN = 403,
NOT_FOUND = 404,
INTERNAL_SERVER_ERROR = 500,
SERVICE_UNAVAILABLE = 503,
}
to template type that will have only numbers like
TypeFromEnum = 200 | 400 | 500 | ... ---> numbers
i only interested in enum transformation without switching to plain Object with "as const"
as consttrick. Withconst statusCodes = { OK: 200, … } as const,type StatusCode = keyof typeof statusCodesgives you the enum as a union type and then you can dotype TypeFromEnum = (typeof statusCodes)[StatusCode]. Any particular reason why you want to avoid this?200you should always and only be usingStatusCodeEnum.OK. If you really need a bare200then enums are not the right solution for your use case. Anyway, for the question as asked... right now there's no plausible way to do what you want programmatically, although if ms/TS#48094 is merged there will be.StatusCodeEnumvalues to a negative number or a non-integer or a very big number you'd miss things. It's easier and better to just write the type out manually.