UNPKG

28.5 kBTypeScriptView Raw
1/**
2 * An *action* is a plain object that represents an intention to change the
3 * state. Actions are the only way to get data into the store. Any data,
4 * whether from UI events, network callbacks, or other sources such as
5 * WebSockets needs to eventually be dispatched as actions.
6 *
7 * Actions must have a `type` field that indicates the type of action being
8 * performed. Types can be defined as constants and imported from another
9 * module. It's better to use strings for `type` than Symbols because strings
10 * are serializable.
11 *
12 * Other than `type`, the structure of an action object is really up to you.
13 * If you're interested, check out Flux Standard Action for recommendations on
14 * how actions should be constructed.
15 *
16 * @template T the type of the action's `type` tag.
17 */
18export interface Action<T = any> {
19 type: T
20}
21
22/**
23 * An Action type which accepts any other properties.
24 * This is mainly for the use of the `Reducer` type.
25 * This is not part of `Action` itself to prevent types that extend `Action` from
26 * having an index signature.
27 */
28export interface AnyAction extends Action {
29 // Allows any extra properties to be defined in an action.
30 [extraProps: string]: any
31}
32
33/**
34 * Internal "virtual" symbol used to make the `CombinedState` type unique.
35 */
36declare const $CombinedState: unique symbol
37
38/**
39 * State base type for reducers created with `combineReducers()`.
40 *
41 * This type allows the `createStore()` method to infer which levels of the
42 * preloaded state can be partial.
43 *
44 * Because Typescript is really duck-typed, a type needs to have some
45 * identifying property to differentiate it from other types with matching
46 * prototypes for type checking purposes. That's why this type has the
47 * `$CombinedState` symbol property. Without the property, this type would
48 * match any object. The symbol doesn't really exist because it's an internal
49 * (i.e. not exported), and internally we never check its value. Since it's a
50 * symbol property, it's not expected to be unumerable, and the value is
51 * typed as always undefined, so its never expected to have a meaningful
52 * value anyway. It just makes this type distinquishable from plain `{}`.
53 */
54interface EmptyObject {
55 readonly [$CombinedState]?: undefined
56}
57export type CombinedState<S> = EmptyObject & S
58
59/**
60 * Recursively makes combined state objects partial. Only combined state _root
61 * objects_ (i.e. the generated higher level object with keys mapping to
62 * individual reducers) are partial.
63 */
64export type PreloadedState<S> = Required<S> extends EmptyObject
65 ? S extends CombinedState<infer S1>
66 ? {
67 [K in keyof S1]?: S1[K] extends object ? PreloadedState<S1[K]> : S1[K]
68 }
69 : S
70 : {
71 [K in keyof S]: S[K] extends string | number | boolean | symbol
72 ? S[K]
73 : PreloadedState<S[K]>
74 }
75
76/* reducers */
77
78/**
79 * A *reducer* (also called a *reducing function*) is a function that accepts
80 * an accumulation and a value and returns a new accumulation. They are used
81 * to reduce a collection of values down to a single value
82 *
83 * Reducers are not unique to Redux—they are a fundamental concept in
84 * functional programming. Even most non-functional languages, like
85 * JavaScript, have a built-in API for reducing. In JavaScript, it's
86 * `Array.prototype.reduce()`.
87 *
88 * In Redux, the accumulated value is the state object, and the values being
89 * accumulated are actions. Reducers calculate a new state given the previous
90 * state and an action. They must be *pure functions*—functions that return
91 * the exact same output for given inputs. They should also be free of
92 * side-effects. This is what enables exciting features like hot reloading and
93 * time travel.
94 *
95 * Reducers are the most important concept in Redux.
96 *
97 * *Do not put API calls into reducers.*
98 *
99 * @template S The type of state consumed and produced by this reducer.
100 * @template A The type of actions the reducer can potentially respond to.
101 */
102export type Reducer<S = any, A extends Action = AnyAction> = (
103 state: S | undefined,
104 action: A
105) => S
106
107/**
108 * Object whose values correspond to different reducer functions.
109 *
110 * @template A The type of actions the reducers can potentially respond to.
111 */
112export type ReducersMapObject<S = any, A extends Action = Action> = {
113 [K in keyof S]: Reducer<S[K], A>
114}
115
116/**
117 * Infer a combined state shape from a `ReducersMapObject`.
118 *
119 * @template M Object map of reducers as provided to `combineReducers(map: M)`.
120 */
121export type StateFromReducersMapObject<M> = M extends ReducersMapObject<
122 any,
123 any
124>
125 ? { [P in keyof M]: M[P] extends Reducer<infer S, any> ? S : never }
126 : never
127
128/**
129 * Infer reducer union type from a `ReducersMapObject`.
130 *
131 * @template M Object map of reducers as provided to `combineReducers(map: M)`.
132 */
133export type ReducerFromReducersMapObject<M> = M extends {
134 [P in keyof M]: infer R
135}
136 ? R extends Reducer<any, any>
137 ? R
138 : never
139 : never
140
141/**
142 * Infer action type from a reducer function.
143 *
144 * @template R Type of reducer.
145 */
146export type ActionFromReducer<R> = R extends Reducer<any, infer A> ? A : never
147
148/**
149 * Infer action union type from a `ReducersMapObject`.
150 *
151 * @template M Object map of reducers as provided to `combineReducers(map: M)`.
152 */
153export type ActionFromReducersMapObject<M> = M extends ReducersMapObject<
154 any,
155 any
156>
157 ? ActionFromReducer<ReducerFromReducersMapObject<M>>
158 : never
159
160/**
161 * Turns an object whose values are different reducer functions, into a single
162 * reducer function. It will call every child reducer, and gather their results
163 * into a single state object, whose keys correspond to the keys of the passed
164 * reducer functions.
165 *
166 * @template S Combined state object type.
167 *
168 * @param reducers An object whose values correspond to different reducer
169 * functions that need to be combined into one. One handy way to obtain it
170 * is to use ES6 `import * as reducers` syntax. The reducers may never
171 * return undefined for any action. Instead, they should return their
172 * initial state if the state passed to them was undefined, and the current
173 * state for any unrecognized action.
174 *
175 * @returns A reducer function that invokes every reducer inside the passed
176 * object, and builds a state object with the same shape.
177 */
178export function combineReducers<S>(
179 reducers: ReducersMapObject<S, any>
180): Reducer<CombinedState<S>>
181export function combineReducers<S, A extends Action = AnyAction>(
182 reducers: ReducersMapObject<S, A>
183): Reducer<CombinedState<S>, A>
184export function combineReducers<M extends ReducersMapObject<any, any>>(
185 reducers: M
186): Reducer<
187 CombinedState<StateFromReducersMapObject<M>>,
188 ActionFromReducersMapObject<M>
189>
190
191/* store */
192
193/**
194 * A *dispatching function* (or simply *dispatch function*) is a function that
195 * accepts an action or an async action; it then may or may not dispatch one
196 * or more actions to the store.
197 *
198 * We must distinguish between dispatching functions in general and the base
199 * `dispatch` function provided by the store instance without any middleware.
200 *
201 * The base dispatch function *always* synchronously sends an action to the
202 * store's reducer, along with the previous state returned by the store, to
203 * calculate a new state. It expects actions to be plain objects ready to be
204 * consumed by the reducer.
205 *
206 * Middleware wraps the base dispatch function. It allows the dispatch
207 * function to handle async actions in addition to actions. Middleware may
208 * transform, delay, ignore, or otherwise interpret actions or async actions
209 * before passing them to the next middleware.
210 *
211 * @template A The type of things (actions or otherwise) which may be
212 * dispatched.
213 */
214export interface Dispatch<A extends Action = AnyAction> {
215 <T extends A>(action: T): T
216}
217
218/**
219 * Function to remove listener added by `Store.subscribe()`.
220 */
221export interface Unsubscribe {
222 (): void
223}
224
225declare global {
226 interface SymbolConstructor {
227 readonly observable: symbol
228 }
229}
230
231/**
232 * A minimal observable of state changes.
233 * For more information, see the observable proposal:
234 * https://github.com/tc39/proposal-observable
235 */
236export type Observable<T> = {
237 /**
238 * The minimal observable subscription method.
239 * @param {Object} observer Any object that can be used as an observer.
240 * The observer object should have a `next` method.
241 * @returns {subscription} An object with an `unsubscribe` method that can
242 * be used to unsubscribe the observable from the store, and prevent further
243 * emission of values from the observable.
244 */
245 subscribe: (observer: Observer<T>) => { unsubscribe: Unsubscribe }
246 [Symbol.observable](): Observable<T>
247}
248
249/**
250 * An Observer is used to receive data from an Observable, and is supplied as
251 * an argument to subscribe.
252 */
253export type Observer<T> = {
254 next?(value: T): void
255}
256
257/**
258 * A store is an object that holds the application's state tree.
259 * There should only be a single store in a Redux app, as the composition
260 * happens on the reducer level.
261 *
262 * @template S The type of state held by this store.
263 * @template A the type of actions which may be dispatched by this store.
264 */
265export interface Store<S = any, A extends Action = AnyAction> {
266 /**
267 * Dispatches an action. It is the only way to trigger a state change.
268 *
269 * The `reducer` function, used to create the store, will be called with the
270 * current state tree and the given `action`. Its return value will be
271 * considered the **next** state of the tree, and the change listeners will
272 * be notified.
273 *
274 * The base implementation only supports plain object actions. If you want
275 * to dispatch a Promise, an Observable, a thunk, or something else, you
276 * need to wrap your store creating function into the corresponding
277 * middleware. For example, see the documentation for the `redux-thunk`
278 * package. Even the middleware will eventually dispatch plain object
279 * actions using this method.
280 *
281 * @param action A plain object representing “what changed”. It is a good
282 * idea to keep actions serializable so you can record and replay user
283 * sessions, or use the time travelling `redux-devtools`. An action must
284 * have a `type` property which may not be `undefined`. It is a good idea
285 * to use string constants for action types.
286 *
287 * @returns For convenience, the same action object you dispatched.
288 *
289 * Note that, if you use a custom middleware, it may wrap `dispatch()` to
290 * return something else (for example, a Promise you can await).
291 */
292 dispatch: Dispatch<A>
293
294 /**
295 * Reads the state tree managed by the store.
296 *
297 * @returns The current state tree of your application.
298 */
299 getState(): S
300
301 /**
302 * Adds a change listener. It will be called any time an action is
303 * dispatched, and some part of the state tree may potentially have changed.
304 * You may then call `getState()` to read the current state tree inside the
305 * callback.
306 *
307 * You may call `dispatch()` from a change listener, with the following
308 * caveats:
309 *
310 * 1. The subscriptions are snapshotted just before every `dispatch()` call.
311 * If you subscribe or unsubscribe while the listeners are being invoked,
312 * this will not have any effect on the `dispatch()` that is currently in
313 * progress. However, the next `dispatch()` call, whether nested or not,
314 * will use a more recent snapshot of the subscription list.
315 *
316 * 2. The listener should not expect to see all states changes, as the state
317 * might have been updated multiple times during a nested `dispatch()` before
318 * the listener is called. It is, however, guaranteed that all subscribers
319 * registered before the `dispatch()` started will be called with the latest
320 * state by the time it exits.
321 *
322 * @param listener A callback to be invoked on every dispatch.
323 * @returns A function to remove this change listener.
324 */
325 subscribe(listener: () => void): Unsubscribe
326
327 /**
328 * Replaces the reducer currently used by the store to calculate the state.
329 *
330 * You might need this if your app implements code splitting and you want to
331 * load some of the reducers dynamically. You might also need this if you
332 * implement a hot reloading mechanism for Redux.
333 *
334 * @param nextReducer The reducer for the store to use instead.
335 */
336 replaceReducer(nextReducer: Reducer<S, A>): void
337
338 /**
339 * Interoperability point for observable/reactive libraries.
340 * @returns {observable} A minimal observable of state changes.
341 * For more information, see the observable proposal:
342 * https://github.com/tc39/proposal-observable
343 */
344 [Symbol.observable](): Observable<S>
345}
346
347export type DeepPartial<T> = {
348 [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]
349}
350
351/**
352 * A store creator is a function that creates a Redux store. Like with
353 * dispatching function, we must distinguish the base store creator,
354 * `createStore(reducer, preloadedState)` exported from the Redux package, from
355 * store creators that are returned from the store enhancers.
356 *
357 * @template S The type of state to be held by the store.
358 * @template A The type of actions which may be dispatched.
359 * @template Ext Store extension that is mixed in to the Store type.
360 * @template StateExt State extension that is mixed into the state type.
361 */
362export interface StoreCreator {
363 <S, A extends Action, Ext, StateExt>(
364 reducer: Reducer<S, A>,
365 enhancer?: StoreEnhancer<Ext, StateExt>
366 ): Store<S & StateExt, A> & Ext
367 <S, A extends Action, Ext, StateExt>(
368 reducer: Reducer<S, A>,
369 preloadedState?: PreloadedState<S>,
370 enhancer?: StoreEnhancer<Ext>
371 ): Store<S & StateExt, A> & Ext
372}
373
374/**
375 * @deprecated
376 *
377 * **We recommend using the `configureStore` method
378 * of the `@reduxjs/toolkit` package**, which replaces `createStore`.
379 *
380 * Redux Toolkit is our recommended approach for writing Redux logic today,
381 * including store setup, reducers, data fetching, and more.
382 *
383 * **For more details, please read this Redux docs page:**
384 * **https://redux.js.org/introduction/why-rtk-is-redux-today**
385 *
386 * `configureStore` from Redux Toolkit is an improved version of `createStore` that
387 * simplifies setup and helps avoid common bugs.
388 *
389 * You should not be using the `redux` core package by itself today, except for learning purposes.
390 * The `createStore` method from the core `redux` package will not be removed, but we encourage
391 * all users to migrate to using Redux Toolkit for all Redux code.
392 *
393 * If you want to use `createStore` without this visual deprecation warning, use
394 * the `legacy_createStore` import instead:
395 *
396 * `import { legacy_createStore as createStore} from 'redux'`
397 *
398 */
399export declare function createStore<S, A extends Action, Ext, StateExt>(
400 reducer: Reducer<S, A>,
401 enhancer?: StoreEnhancer<Ext, StateExt>
402): Store<S & StateExt, A> & Ext
403/**
404 * @deprecated
405 *
406 * **We recommend using the `configureStore` method
407 * of the `@reduxjs/toolkit` package**, which replaces `createStore`.
408 *
409 * Redux Toolkit is our recommended approach for writing Redux logic today,
410 * including store setup, reducers, data fetching, and more.
411 *
412 * **For more details, please read this Redux docs page:**
413 * **https://redux.js.org/introduction/why-rtk-is-redux-today**
414 *
415 * `configureStore` from Redux Toolkit is an improved version of `createStore` that
416 * simplifies setup and helps avoid common bugs.
417 *
418 * You should not be using the `redux` core package by itself today, except for learning purposes.
419 * The `createStore` method from the core `redux` package will not be removed, but we encourage
420 * all users to migrate to using Redux Toolkit for all Redux code.
421 *
422 * If you want to use `createStore` without this visual deprecation warning, use
423 * the `legacy_createStore` import instead:
424 *
425 * `import { legacy_createStore as createStore} from 'redux'`
426 *
427 */
428export declare function createStore<S, A extends Action, Ext, StateExt>(
429 reducer: Reducer<S, A>,
430 preloadedState?: PreloadedState<S>,
431 enhancer?: StoreEnhancer<Ext>
432): Store<S & StateExt, A> & Ext
433
434/**
435 * Creates a Redux store that holds the state tree.
436 *
437 * **We recommend using `configureStore` from the
438 * `@reduxjs/toolkit` package**, which replaces `createStore`:
439 * **https://redux.js.org/introduction/why-rtk-is-redux-today**
440 *
441 * The only way to change the data in the store is to call `dispatch()` on it.
442 *
443 * There should only be a single store in your app. To specify how different
444 * parts of the state tree respond to actions, you may combine several reducers
445 * into a single reducer function by using `combineReducers`.
446 *
447 * @param {Function} reducer A function that returns the next state tree, given
448 * the current state tree and the action to handle.
449 *
450 * @param {any} [preloadedState] The initial state. You may optionally specify it
451 * to hydrate the state from the server in universal apps, or to restore a
452 * previously serialized user session.
453 * If you use `combineReducers` to produce the root reducer function, this must be
454 * an object with the same shape as `combineReducers` keys.
455 *
456 * @param {Function} [enhancer] The store enhancer. You may optionally specify it
457 * to enhance the store with third-party capabilities such as middleware,
458 * time travel, persistence, etc. The only store enhancer that ships with Redux
459 * is `applyMiddleware()`.
460 *
461 * @returns {Store} A Redux store that lets you read the state, dispatch actions
462 * and subscribe to changes.
463 */
464export declare function legacy_createStore<S, A extends Action, Ext, StateExt>(
465 reducer: Reducer<S, A>,
466 enhancer?: StoreEnhancer<Ext, StateExt>
467): Store<S & StateExt, A> & Ext
468/**
469 * Creates a Redux store that holds the state tree.
470 *
471 * **We recommend using `configureStore` from the
472 * `@reduxjs/toolkit` package**, which replaces `createStore`:
473 * **https://redux.js.org/introduction/why-rtk-is-redux-today**
474 *
475 * The only way to change the data in the store is to call `dispatch()` on it.
476 *
477 * There should only be a single store in your app. To specify how different
478 * parts of the state tree respond to actions, you may combine several reducers
479 * into a single reducer function by using `combineReducers`.
480 *
481 * @param {Function} reducer A function that returns the next state tree, given
482 * the current state tree and the action to handle.
483 *
484 * @param {any} [preloadedState] The initial state. You may optionally specify it
485 * to hydrate the state from the server in universal apps, or to restore a
486 * previously serialized user session.
487 * If you use `combineReducers` to produce the root reducer function, this must be
488 * an object with the same shape as `combineReducers` keys.
489 *
490 * @param {Function} [enhancer] The store enhancer. You may optionally specify it
491 * to enhance the store with third-party capabilities such as middleware,
492 * time travel, persistence, etc. The only store enhancer that ships with Redux
493 * is `applyMiddleware()`.
494 *
495 * @returns {Store} A Redux store that lets you read the state, dispatch actions
496 * and subscribe to changes.
497 */
498export declare function legacy_createStore<S, A extends Action, Ext, StateExt>(
499 reducer: Reducer<S, A>,
500 preloadedState?: PreloadedState<S>,
501 enhancer?: StoreEnhancer<Ext>
502): Store<S & StateExt, A> & Ext
503
504/**
505 * A store enhancer is a higher-order function that composes a store creator
506 * to return a new, enhanced store creator. This is similar to middleware in
507 * that it allows you to alter the store interface in a composable way.
508 *
509 * Store enhancers are much the same concept as higher-order components in
510 * React, which are also occasionally called “component enhancers”.
511 *
512 * Because a store is not an instance, but rather a plain-object collection of
513 * functions, copies can be easily created and modified without mutating the
514 * original store. There is an example in `compose` documentation
515 * demonstrating that.
516 *
517 * Most likely you'll never write a store enhancer, but you may use the one
518 * provided by the developer tools. It is what makes time travel possible
519 * without the app being aware it is happening. Amusingly, the Redux
520 * middleware implementation is itself a store enhancer.
521 *
522 * @template Ext Store extension that is mixed into the Store type.
523 * @template StateExt State extension that is mixed into the state type.
524 */
525export type StoreEnhancer<Ext = {}, StateExt = {}> = (
526 next: StoreEnhancerStoreCreator
527) => StoreEnhancerStoreCreator<Ext, StateExt>
528export type StoreEnhancerStoreCreator<Ext = {}, StateExt = {}> = <
529 S = any,
530 A extends Action = AnyAction
531>(
532 reducer: Reducer<S, A>,
533 preloadedState?: PreloadedState<S>
534) => Store<S & StateExt, A> & Ext
535
536/* middleware */
537
538export interface MiddlewareAPI<D extends Dispatch = Dispatch, S = any> {
539 dispatch: D
540 getState(): S
541}
542
543/**
544 * A middleware is a higher-order function that composes a dispatch function
545 * to return a new dispatch function. It often turns async actions into
546 * actions.
547 *
548 * Middleware is composable using function composition. It is useful for
549 * logging actions, performing side effects like routing, or turning an
550 * asynchronous API call into a series of synchronous actions.
551 *
552 * @template DispatchExt Extra Dispatch signature added by this middleware.
553 * @template S The type of the state supported by this middleware.
554 * @template D The type of Dispatch of the store where this middleware is
555 * installed.
556 */
557export interface Middleware<
558 DispatchExt = {},
559 S = any,
560 D extends Dispatch = Dispatch
561> {
562 (api: MiddlewareAPI<D, S>): (
563 next: Dispatch<AnyAction>
564 ) => (action: any) => any
565}
566
567/**
568 * Creates a store enhancer that applies middleware to the dispatch method
569 * of the Redux store. This is handy for a variety of tasks, such as
570 * expressing asynchronous actions in a concise manner, or logging every
571 * action payload.
572 *
573 * See `redux-thunk` package as an example of the Redux middleware.
574 *
575 * Because middleware is potentially asynchronous, this should be the first
576 * store enhancer in the composition chain.
577 *
578 * Note that each middleware will be given the `dispatch` and `getState`
579 * functions as named arguments.
580 *
581 * @param middlewares The middleware chain to be applied.
582 * @returns A store enhancer applying the middleware.
583 *
584 * @template Ext Dispatch signature added by a middleware.
585 * @template S The type of the state supported by a middleware.
586 */
587export function applyMiddleware(): StoreEnhancer
588export function applyMiddleware<Ext1, S>(
589 middleware1: Middleware<Ext1, S, any>
590): StoreEnhancer<{ dispatch: Ext1 }>
591export function applyMiddleware<Ext1, Ext2, S>(
592 middleware1: Middleware<Ext1, S, any>,
593 middleware2: Middleware<Ext2, S, any>
594): StoreEnhancer<{ dispatch: Ext1 & Ext2 }>
595export function applyMiddleware<Ext1, Ext2, Ext3, S>(
596 middleware1: Middleware<Ext1, S, any>,
597 middleware2: Middleware<Ext2, S, any>,
598 middleware3: Middleware<Ext3, S, any>
599): StoreEnhancer<{ dispatch: Ext1 & Ext2 & Ext3 }>
600export function applyMiddleware<Ext1, Ext2, Ext3, Ext4, S>(
601 middleware1: Middleware<Ext1, S, any>,
602 middleware2: Middleware<Ext2, S, any>,
603 middleware3: Middleware<Ext3, S, any>,
604 middleware4: Middleware<Ext4, S, any>
605): StoreEnhancer<{ dispatch: Ext1 & Ext2 & Ext3 & Ext4 }>
606export function applyMiddleware<Ext1, Ext2, Ext3, Ext4, Ext5, S>(
607 middleware1: Middleware<Ext1, S, any>,
608 middleware2: Middleware<Ext2, S, any>,
609 middleware3: Middleware<Ext3, S, any>,
610 middleware4: Middleware<Ext4, S, any>,
611 middleware5: Middleware<Ext5, S, any>
612): StoreEnhancer<{ dispatch: Ext1 & Ext2 & Ext3 & Ext4 & Ext5 }>
613export function applyMiddleware<Ext, S = any>(
614 ...middlewares: Middleware<any, S, any>[]
615): StoreEnhancer<{ dispatch: Ext }>
616
617/* action creators */
618
619/**
620 * An *action creator* is, quite simply, a function that creates an action. Do
621 * not confuse the two terms—again, an action is a payload of information, and
622 * an action creator is a factory that creates an action.
623 *
624 * Calling an action creator only produces an action, but does not dispatch
625 * it. You need to call the store's `dispatch` function to actually cause the
626 * mutation. Sometimes we say *bound action creators* to mean functions that
627 * call an action creator and immediately dispatch its result to a specific
628 * store instance.
629 *
630 * If an action creator needs to read the current state, perform an API call,
631 * or cause a side effect, like a routing transition, it should return an
632 * async action instead of an action.
633 *
634 * @template A Returned action type.
635 */
636export interface ActionCreator<A> {
637 (...args: any[]): A
638}
639
640/**
641 * Object whose values are action creator functions.
642 */
643export interface ActionCreatorsMapObject<A = any> {
644 [key: string]: ActionCreator<A>
645}
646
647/**
648 * Turns an object whose values are action creators, into an object with the
649 * same keys, but with every function wrapped into a `dispatch` call so they
650 * may be invoked directly. This is just a convenience method, as you can call
651 * `store.dispatch(MyActionCreators.doSomething())` yourself just fine.
652 *
653 * For convenience, you can also pass a single function as the first argument,
654 * and get a function in return.
655 *
656 * @param actionCreator An object whose values are action creator functions.
657 * One handy way to obtain it is to use ES6 `import * as` syntax. You may
658 * also pass a single function.
659 *
660 * @param dispatch The `dispatch` function available on your Redux store.
661 *
662 * @returns The object mimicking the original object, but with every action
663 * creator wrapped into the `dispatch` call. If you passed a function as
664 * `actionCreator`, the return value will also be a single function.
665 */
666export function bindActionCreators<A, C extends ActionCreator<A>>(
667 actionCreator: C,
668 dispatch: Dispatch
669): C
670
671export function bindActionCreators<
672 A extends ActionCreator<any>,
673 B extends ActionCreator<any>
674>(actionCreator: A, dispatch: Dispatch): B
675
676export function bindActionCreators<A, M extends ActionCreatorsMapObject<A>>(
677 actionCreators: M,
678 dispatch: Dispatch
679): M
680
681export function bindActionCreators<
682 M extends ActionCreatorsMapObject<any>,
683 N extends ActionCreatorsMapObject<any>
684>(actionCreators: M, dispatch: Dispatch): N
685
686/* compose */
687
688type Func0<R> = () => R
689type Func1<T1, R> = (a1: T1) => R
690type Func2<T1, T2, R> = (a1: T1, a2: T2) => R
691type Func3<T1, T2, T3, R> = (a1: T1, a2: T2, a3: T3, ...args: any[]) => R
692
693/**
694 * Composes single-argument functions from right to left. The rightmost
695 * function can take multiple arguments as it provides the signature for the
696 * resulting composite function.
697 *
698 * @param funcs The functions to compose.
699 * @returns R function obtained by composing the argument functions from right
700 * to left. For example, `compose(f, g, h)` is identical to doing
701 * `(...args) => f(g(h(...args)))`.
702 */
703export function compose(): <R>(a: R) => R
704
705export function compose<F extends Function>(f: F): F
706
707/* two functions */
708export function compose<A, R>(f1: (b: A) => R, f2: Func0<A>): Func0<R>
709export function compose<A, T1, R>(
710 f1: (b: A) => R,
711 f2: Func1<T1, A>
712): Func1<T1, R>
713export function compose<A, T1, T2, R>(
714 f1: (b: A) => R,
715 f2: Func2<T1, T2, A>
716): Func2<T1, T2, R>
717export function compose<A, T1, T2, T3, R>(
718 f1: (b: A) => R,
719 f2: Func3<T1, T2, T3, A>
720): Func3<T1, T2, T3, R>
721
722/* three functions */
723export function compose<A, B, R>(
724 f1: (b: B) => R,
725 f2: (a: A) => B,
726 f3: Func0<A>
727): Func0<R>
728export function compose<A, B, T1, R>(
729 f1: (b: B) => R,
730 f2: (a: A) => B,
731 f3: Func1<T1, A>
732): Func1<T1, R>
733export function compose<A, B, T1, T2, R>(
734 f1: (b: B) => R,
735 f2: (a: A) => B,
736 f3: Func2<T1, T2, A>
737): Func2<T1, T2, R>
738export function compose<A, B, T1, T2, T3, R>(
739 f1: (b: B) => R,
740 f2: (a: A) => B,
741 f3: Func3<T1, T2, T3, A>
742): Func3<T1, T2, T3, R>
743
744/* four functions */
745export function compose<A, B, C, R>(
746 f1: (b: C) => R,
747 f2: (a: B) => C,
748 f3: (a: A) => B,
749 f4: Func0<A>
750): Func0<R>
751export function compose<A, B, C, T1, R>(
752 f1: (b: C) => R,
753 f2: (a: B) => C,
754 f3: (a: A) => B,
755 f4: Func1<T1, A>
756): Func1<T1, R>
757export function compose<A, B, C, T1, T2, R>(
758 f1: (b: C) => R,
759 f2: (a: B) => C,
760 f3: (a: A) => B,
761 f4: Func2<T1, T2, A>
762): Func2<T1, T2, R>
763export function compose<A, B, C, T1, T2, T3, R>(
764 f1: (b: C) => R,
765 f2: (a: B) => C,
766 f3: (a: A) => B,
767 f4: Func3<T1, T2, T3, A>
768): Func3<T1, T2, T3, R>
769
770/* rest */
771export function compose<R>(
772 f1: (b: any) => R,
773 ...funcs: Function[]
774): (...args: any[]) => R
775
776export function compose<R>(...funcs: Function[]): (...args: any[]) => R
777
\No newline at end of file