configureStore.d.ts 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import type { Reducer, ReducersMapObject, Middleware, Action, StoreEnhancer, Store, UnknownAction } from 'redux';
  2. import type { DevToolsEnhancerOptions as DevToolsOptions } from './devtoolsExtension';
  3. import type { ThunkMiddlewareFor, GetDefaultMiddleware } from './getDefaultMiddleware';
  4. import type { ExtractDispatchExtensions, ExtractStoreExtensions, ExtractStateExtensions } from './tsHelpers';
  5. import type { Tuple } from './utils';
  6. import type { GetDefaultEnhancers } from './getDefaultEnhancers';
  7. /**
  8. * Options for `configureStore()`.
  9. *
  10. * @public
  11. */
  12. export interface ConfigureStoreOptions<S = any, A extends Action = UnknownAction, M extends Tuple<Middlewares<S>> = Tuple<Middlewares<S>>, E extends Tuple<Enhancers> = Tuple<Enhancers>, P = S> {
  13. /**
  14. * A single reducer function that will be used as the root reducer, or an
  15. * object of slice reducers that will be passed to `combineReducers()`.
  16. */
  17. reducer: Reducer<S, A, P> | ReducersMapObject<S, A, P>;
  18. /**
  19. * An array of Redux middleware to install, or a callback receiving `getDefaultMiddleware` and returning a Tuple of middleware.
  20. * If not supplied, defaults to the set of middleware returned by `getDefaultMiddleware()`.
  21. *
  22. * @example `middleware: (gDM) => gDM().concat(logger, apiMiddleware, yourCustomMiddleware)`
  23. * @see https://redux-toolkit.js.org/api/getDefaultMiddleware#intended-usage
  24. */
  25. middleware?: (getDefaultMiddleware: GetDefaultMiddleware<S>) => M;
  26. /**
  27. * Whether to enable Redux DevTools integration. Defaults to `true`.
  28. *
  29. * Additional configuration can be done by passing Redux DevTools options
  30. */
  31. devTools?: boolean | DevToolsOptions;
  32. /**
  33. * The initial state, same as Redux's createStore.
  34. * You may optionally specify it to hydrate the state
  35. * from the server in universal apps, or to restore a previously serialized
  36. * user session. If you use `combineReducers()` to produce the root reducer
  37. * function (either directly or indirectly by passing an object as `reducer`),
  38. * this must be an object with the same shape as the reducer map keys.
  39. */
  40. preloadedState?: P;
  41. /**
  42. * The store enhancers to apply. See Redux's `createStore()`.
  43. * All enhancers will be included before the DevTools Extension enhancer.
  44. * If you need to customize the order of enhancers, supply a callback
  45. * function that will receive a `getDefaultEnhancers` function that returns a Tuple,
  46. * and should return a Tuple of enhancers (such as `getDefaultEnhancers().concat(offline)`).
  47. * If you only need to add middleware, you can use the `middleware` parameter instead.
  48. */
  49. enhancers?: (getDefaultEnhancers: GetDefaultEnhancers<M>) => E;
  50. }
  51. export type Middlewares<S> = ReadonlyArray<Middleware<{}, S>>;
  52. type Enhancers = ReadonlyArray<StoreEnhancer>;
  53. /**
  54. * A Redux store returned by `configureStore()`. Supports dispatching
  55. * side-effectful _thunks_ in addition to plain actions.
  56. *
  57. * @public
  58. */
  59. export type EnhancedStore<S = any, A extends Action = UnknownAction, E extends Enhancers = Enhancers> = ExtractStoreExtensions<E> & Store<S & ExtractStateExtensions<E>, A>;
  60. /**
  61. * A friendly abstraction over the standard Redux `createStore()` function.
  62. *
  63. * @param options The store configuration.
  64. * @returns A configured Redux store.
  65. *
  66. * @public
  67. */
  68. export declare function configureStore<S = any, A extends Action = UnknownAction, M extends Tuple<Middlewares<S>> = Tuple<[ThunkMiddlewareFor<S>]>, E extends Tuple<Enhancers> = Tuple<[
  69. StoreEnhancer<{
  70. dispatch: ExtractDispatchExtensions<M>;
  71. }>,
  72. StoreEnhancer
  73. ]>, P = S>(options: ConfigureStoreOptions<S, A, M, E, P>): EnhancedStore<S, A, E>;
  74. export {};