extend-redux.d.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { ThunkAction } from './src/index'
  2. /**
  3. * Globally alter the Redux `bindActionCreators` and `Dispatch` types to assume
  4. * that the thunk middleware always exists, for ease of use.
  5. * This is kept as a separate file that may be optionally imported, to
  6. * avoid polluting the default types in case the thunk middleware is _not_
  7. * actually being used.
  8. *
  9. * To add these types to your app:
  10. * import 'redux-thunk/extend-redux'
  11. */
  12. declare module 'redux' {
  13. /**
  14. * Overload for bindActionCreators redux function, returns expects responses
  15. * from thunk actions
  16. */
  17. function bindActionCreators<
  18. ActionCreators extends ActionCreatorsMapObject<any>
  19. >(
  20. actionCreators: ActionCreators,
  21. dispatch: Dispatch
  22. ): {
  23. [ActionCreatorName in keyof ActionCreators]: ReturnType<
  24. ActionCreators[ActionCreatorName]
  25. > extends ThunkAction<any, any, any, any>
  26. ? (
  27. ...args: Parameters<ActionCreators[ActionCreatorName]>
  28. ) => ReturnType<ReturnType<ActionCreators[ActionCreatorName]>>
  29. : ActionCreators[ActionCreatorName]
  30. }
  31. /*
  32. * Overload to add thunk support to Redux's dispatch() function.
  33. * Useful for react-redux or any other library which could use this type.
  34. */
  35. export interface Dispatch<A extends Action = AnyAction> {
  36. <ReturnType = any, State = any, ExtraThunkArg = any>(
  37. thunkAction: ThunkAction<ReturnType, State, ExtraThunkArg, A>
  38. ): ReturnType
  39. }
  40. }