Given the following pattern where a const is created from a set of enums:
enum ServiceKeys {
SERVICE1 = 'Service1',
SERVICE2 = 'Service2',
}
enum Service1Actions {
ADD = 1,
}
enum Service2Actions {
DELETE = 1,
}
const serviceActions = {
[ServiceKeys.SERVICE1]: Service1Actions,
[ServiceKeys.SERVICE2]: Service2Actions,
}
I would like to produce a union type of all the enums in the const that is equivalent to:
type AnyServiceAction = Service1Actions | Service2Actions;
The end goal is to use this type for creating a config. I have reduced my code to its simplest form in order to demonstrate, but this is basically how it is supposed to work. Of course, in its original form, there are many more properties associated to the specified action.
class Entry {
public readonly action: AnyServiceAction | null;
constructor(action: AnyServiceAction = null) {
this.action = action;
}
}
And so the config is constructed in this manner:
class Config {
public readonly [ServiceKeys.SERVICE1]: Entry[] = [
new Entry(serviceActions[ServiceKeys.SERVICE1].ADD),
];
}