Is there a way to create a function that can work with any enum and function that accepts it as an argument? Consider the following scenario:
enum Enum1 {
VALUE1 = "value1"
}
enum Enum2 {
VALUE2 = "value2"
}
const func1 = (e: Enum1) => e;
const func2 = (e: Enum2) => e.toUpperCase();
const genericFunc = (e: Enum1 | Enum2, func: (e: Enum1 | Enum2) => typeof e) => func(e);
console.log(genericFunc(Enum1.VALUE1, func1)); // error with func1
console.log(genericFunc(Enum2.VALUE2, func2)); // error with func2
Is there a way to make this approach more flexible without resorting to using any
?