D
D
DanceMonkeyTime2020-07-07 14:58:18
typescript
DanceMonkeyTime, 2020-07-07 14:58:18

What is the best way for me to style Union types for actions?

I have an enum with action names:

export enum ResearchActionTypes {
  SAVE_CATEGORY = 'SAVE_CATEGORY',
  SAVE_PROJECT_NAME = 'SAVE_PROJECT_NAME',
  SAVE_BRIEF = 'SAVE_BRIEF',
  SAVE_USER_INFO = 'SAVE_USER_INFO',
  UPDATE_LOCAL_PATH = 'UPDATE_LOCAL_PATH',
  SAVE_REPORT_TYPE = 'SAVE_REPORT_TYPE',
  SAVE_OBJECTIVES = 'SAVE_OBJECTIVES',
  SAVE_ACTIVE_CHAPTER = 'SAVE_ACTIVE_CHAPTER',
  SAVE_INDUSTRIES = 'SAVE_INDUSTRIES',
  SAVE_TARGET = 'SAVE_TARGET',
  SAVE_REGIONS = 'SAVE_REGIONS',
  SAVE_PRESET_TAGS = 'SAVE_PRESET_TAGS',
  UPDATE_SCREEN_STEP = 'UPDATE_SCREEN_STEP',
}


I want to make the ResearchActions type via Union so that I can use it later in the reducer.
What is the best way to do this so that I don’t have to write constants first

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2020-07-07
@DanceMonkeyTime

export type SaveCategoryAction = {
    type: 'SAVE_CATEGORY',
    foo: number;
    // .....
}

export type SaveProjectNameAction = {
    type: 'SAVE_PROJECT_NAME',
    bar: string;
    // .....
}

export type ResearchAction = SaveCategoryAction | SaveProjectNameAction;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question