I would like to declare an interface with a member of type enum, as in - any enum. The idea here is to be a little safer than saying any, but still open to future enum types.
Use case:
I'm defining an action interface for redux, and I want the BaseAction interface to be something like this:
export interface BaseAction {
type: enum; //this gives an error
payload: any;
}
Is there a way to declare that the type of a member is any so long as it's an enum?
This way, in the future, I may define this:
export enum SpecificActionType {
SPECIFIC_1 = "SPECIFIC_ACTION_1",
SPECIFIC_2 = "SPECIFIC_ACTION_2",
}
export interface SpecificAction1 extends BaseAction {
type: SpecificActionType.SPECIFIC_1;
payload: {
id;
};
}
As a disclaimer, I'm all new to redux and typescript, but looking for a good rigorous and future proof paradigm that's developer friendly. If you have a better idea, I'm open to that as well.