title: What is "a great way" to write this discriminated union, minimizing repetition?
body: <p>This is coming out of a simple react native screen, but what I'm looking for is a pattern/template that accomplishes this goal:</p>
  
  <ul>
  <li>Action type, a discriminated union for each redux action</li>
  <li>functions to create each Action</li>
  </ul>
  
  <p>I've tried a few patterns and haven't found one I like, but I'm new to TypeScript (I'm coming from Swift and Elm) and so I thought someone would have a great solution.  Here's what I'm using now:</p>
  
  <pre class="lang-typescript prettyprint-override"><code>enum Name {
    SET_CURRENT_LOCATION = "main.SET_CURRENT_LOCATION",
    SET_IS_MODAL_VISIBLE = "main.SET_IS_MODAL_VISIBLE",
    TOGGLE_MODAL_VISIBLE = "main.TOGGLE_MODAL_VISIBLE",
  }
  
  type SetCurrentLocation = { name: Name.SET_CURRENT_LOCATION; value: LocationData | null }
  type SetModalVisible = { name: Name.SET_IS_MODAL_VISIBLE; value: boolean }
  type ToggleModalVisible = { name: Name.TOGGLE_MODAL_VISIBLE }
  
  export type Action =
    | SetCurrentLocation
    | SetModalVisible
    | ToggleModalVisible
  
  export function setCurrentLocation(value: LocationData | null): Action {
    return {
      name: Name.SET_CURRENT_LOCATION,
      value,
    }
  }
  
  export function showModal(): Action {
    return {
      name: Name.SET_IS_MODAL_VISIBLE,
      value: true,
    }
  }
  
  export function hideModal(): Action {
    return {
      name: Name.SET_IS_MODAL_VISIBLE,
      value: false,
    }
  }
  
  export function toggleModal(): Action {
    return {
      name: Name.TOGGLE_MODAL_VISIBLE,
    }
  }
  
  export function reducer(state: State, action: Action): State {
    switch (action.name) {
      case Name.SET_CURRENT_LOCATION:
        return { ...state, currentLocation: action.value }
      case Name.SET_IS_MODAL_VISIBLE:
        return { ...state, isModalVisible: action.value }
      case Name.TOGGLE_MODAL_VISIBLE:
        return { ...state, isModalVisible: !state.isModalVisible }
    }
  }
  </code></pre>
  
  <p>This is a <strong>best practice / elegant patterns</strong> question, not a data modeling one.  Please excuse any copy/paste errors.</p>
  
  <p><em>Edit:</em> I removed the pseudo-code second snippet because it detracted from the question and added confusion</p>