Is it possible to convert a union type to a map with the key being "type" property? e.g. Given a union type Actions:
type Actions =
| {
type: 'campaignCreated';
code: string;
}
| {
type: 'campaignEnded';
amount: number;
};
I'd like to be able to receive;
type ActionMap = {
campaignCreated: {
type: 'campaignCreated';
code: string;
};
campaignEnded: {
type: 'campaignEnded';
amount: number;
};
};