UNPKG

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