UNPKG

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