index.d.ts 28 KB

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