Hey, I have the type following:
export enum AutomationActionType {
RoleAdd = 1,
RoleRemove = 2,
Message = 3,
}
export type AnyAutomationActionType = AutomationActionType.RoleAdd | AutomationActionType.RoleRemove | AutomationActionType.Message;
export type AutomationComponentData<
T extends AutomationActionType = AnyAutomationActionType
> = {
componentType: ComponentType;
actionType: T;
label: string;
data: T extends AutomationActionType.RoleAdd
? AutomationRoleActionData
: T extends AutomationActionType.RoleRemove
? AutomationRoleActionData
: T extends AutomationActionType.Message
? AutomationMessageActionData : T
};
And I wanted to check the type of AutomationComponentData with:
if (component.actionType === AutomationActionType.RoleAdd)
But still, ts does not recognize component as AutomationActionType<AutomationActionType.RoleAdd> but AutomationActionType<AnyAutomationActionType>.
I have no idea if i am doing a good practice with generics.
any suggestion on checking type of generics as I intend?