title: How to get the AppDispatch Typescript type in redux toolkit when store is initialized with a function?
body: <p>Today my <code>AppDispatch</code> type is extracted from <code>store.dispatch</code>:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { configureStore, combineReducers } from "@reduxjs/toolkit";
  import auth from "./auth/authSlice";
  const rootReducer = combineReducers({ auth });
  const store = configureStore({
    reducer: rootReducer
  });
  export type RootState = ReturnType&lt;typeof rootReducer&gt;;
  export type AppDispatch = typeof store.dispatch;
  export default store;
  </code></pre>
  
  <p>Now I try to replace store with initStore function. I want to rehydrate my store using preloadedState.</p>
  
  <pre class="lang-js prettyprint-override"><code>import { configureStore, combineReducers } from "@reduxjs/toolkit";
  import auth from "./auth/authSlice";
  const rootReducer = combineReducers({ auth });
  const store = (preloadedState={}) =&gt; {
    return configureStore({
      reducer: rootReducer,
      preloadedState,
    });
  }
  export type RootState = ReturnType&lt;typeof rootReducer&gt;;
  export type AppDispatch = typeof store.dispatch;
  export default store;
  </code></pre>
  
  <p>I have an error:</p>
  
  <pre><code>Property 'dispatch' does not exist on type '(preloadedState?: {}) =&gt; EnhancedStore&lt;CombinedState&lt;{ auth: AuthState; }&gt;, AnyAction, [ThunkMiddleware&lt;CombinedState&lt;{ auth: AuthState; }&gt;, AnyAction, null&gt; | ThunkMiddleware&lt;...&gt;]&gt;'.ts(2339)
  </code></pre>
  
  <p>How can I get the AppDispatch type correctly ?</p>