title: Redux: Payload type guess by key of Record
body: <p>Initial code:
  <a href="https://codesandbox.io/s/typescript-playground-export-forked-2nwwx?file=/index.ts" rel="nofollow noreferrer">(Full example)</a></p>
  <p><code>createReducer</code> function typed params with initial storage and reducer name:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>export function createReducer&lt;T extends keyof ActionsPayload, R extends keyof AppState&gt;(
    initialState: AppState[R],
    handlers: Pick&lt;
      Record&lt;T, (state: AppState[R], props: {payload: ActionsPayload[T]}) =&gt; AppState[R]&gt;,
      T
    &gt;
  ) {
    return function reducer(
      state = initialState,
      action: {type: keyof ActionTypes; payload: ActionsPayload[T]}
    ) {
      if (has(handlers, action.type)) {
        return handlers[action.type](state, action);
      }
  
      return state;
    };
  }</code></pre>
  </div>
  </div>
  </p>
  <p>Goal:</p>
  <p>Create reducer with predefined types of <code>actions</code>(Action types) and <code>payloads</code> with comparison to return type of <code>state</code> like:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>export const feedbacks = createReducer&lt;
    | ActionTypes.FETCH_FEEDBACKS
    | ActionTypes.LOADING_FEEDBACKS
    | ActionTypes.CHANGE_FEEDBACKS_ORDER
    | ActionTypes.CHANGE_FEEDBACKS_PAGE,
    'feedbacks'
  &gt;(initialState.feedbacks, {
    [ActionTypes.FETCH_FEEDBACKS](state, {payload}) {
      return {
        ...state,
        totalFeedbacks: payload?.pageInfo.totalResultsCount,
        list: payload?.results,
        pageSettings: payload?.pageInfo,
        isLoading: false,
      };
    },
    //... etc with more actions</code></pre>
  </div>
  </div>
  </p>
  <p>In full example it's works if give to <code>createReducer</code> one type but if you five multiple <code>ActionTypes</code> it's compares Record to every payload</p>