In order to use a subset of items in a typescript enum, we do something like this:
enum Operator {
EQUAL = 'EQUAL',
NOT_EQUAL = 'NOT_EQUAL',
LESS = 'LESS',
GREATER = 'GREATER',
}
type EqualOperators = Exclude<Operator, Operator.LESS | Operator.GREATER>
Is there any way where I can get EqualOperators to be an enum instead of a type, this way I could use it in a script?
To clarify, when I say "use it in a script", I mean being able to use the enum values in a javascript function, which you can't to with types, e.g. something like this:
enum Operator {
EQUAL = 'EQUAL',
NOT_EQUAL = 'NOT_EQUAL',
LESS = 'LESS',
GREATER = 'GREATER',
}
function getOperator() {
if (Operator.EQUAL) {
return "=";
}
if (Operator.NOT_EQUAL) {
return "!=";
}
throw new Error('invalid operator');
}
Thanks!