UNPKG

4.09 kBTypeScriptView Raw
1import type { Reducer, ReducersMapObject, Middleware, Action, AnyAction, StoreEnhancer, Store, Dispatch, PreloadedState, CombinedState } from 'redux';
2import type { DevToolsEnhancerOptions as DevToolsOptions } from './devtoolsExtension';
3import type { ThunkMiddlewareFor, CurriedGetDefaultMiddleware } from './getDefaultMiddleware';
4import type { NoInfer, ExtractDispatchExtensions, ExtractStoreExtensions } from './tsHelpers';
5/**
6 * Callback function type, to be used in `ConfigureStoreOptions.enhancers`
7 *
8 * @public
9 */
10export declare type ConfigureEnhancersCallback<E extends Enhancers = Enhancers> = (defaultEnhancers: readonly StoreEnhancer[]) => [...E];
11/**
12 * Options for `configureStore()`.
13 *
14 * @public
15 */
16export interface ConfigureStoreOptions<S = any, A extends Action = AnyAction, M extends Middlewares<S> = Middlewares<S>, E extends Enhancers = Enhancers> {
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?: E | ConfigureEnhancersCallback<E>;
54}
55declare type Middlewares<S> = ReadonlyArray<Middleware<{}, S>>;
56declare type Enhancers = ReadonlyArray<StoreEnhancer>;
57export interface ToolkitStore<S = any, A extends Action = AnyAction, M extends Middlewares<S> = Middlewares<S>> extends Store<S, A> {
58 /**
59 * The `dispatch` method of your store, enhanced by all its middlewares.
60 *
61 * @inheritdoc
62 */
63 dispatch: ExtractDispatchExtensions<M> & Dispatch<A>;
64}
65/**
66 * A Redux store returned by `configureStore()`. Supports dispatching
67 * side-effectful _thunks_ in addition to plain actions.
68 *
69 * @public
70 */
71export declare type EnhancedStore<S = any, A extends Action = AnyAction, M extends Middlewares<S> = Middlewares<S>, E extends Enhancers = Enhancers> = ToolkitStore<S, A, M> & ExtractStoreExtensions<E>;
72/**
73 * A friendly abstraction over the standard Redux `createStore()` function.
74 *
75 * @param options The store configuration.
76 * @returns A configured Redux store.
77 *
78 * @public
79 */
80export declare function configureStore<S = any, A extends Action = AnyAction, M extends Middlewares<S> = [ThunkMiddlewareFor<S>], E extends Enhancers = [StoreEnhancer]>(options: ConfigureStoreOptions<S, A, M, E>): EnhancedStore<S, A, M, E>;
81export {};
82
\No newline at end of file