'How can I know at compile-time whether a type is an enum?

I want to write a function that validates that a value is part of an enum, and throw if not. From this answer, I wrote:

    private ensureValueInEnum(enumType: any, value: string): void {
        if (!Object.values(enumType).includes(value)) {
            throw new Exception(`${value} is invalid value. Valid values are: ${Object.values(enumType).join(' / ')}`);
        }
    }

But, I don't like that enumType is any. Is there something I can write that says "enumType is an enum"?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source