getDefaultMiddleware.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import type { AnyAction } from 'redux';
  2. import type { ThunkMiddleware } from 'redux-thunk';
  3. import type { ActionCreatorInvariantMiddlewareOptions } from './actionCreatorInvariantMiddleware';
  4. import type { ImmutableStateInvariantMiddlewareOptions } from './immutableStateInvariantMiddleware';
  5. import type { SerializableStateInvariantMiddlewareOptions } from './serializableStateInvariantMiddleware';
  6. import type { ExcludeFromTuple } from './tsHelpers';
  7. import { MiddlewareArray } from './utils';
  8. interface ThunkOptions<E = any> {
  9. extraArgument: E;
  10. }
  11. interface GetDefaultMiddlewareOptions {
  12. thunk?: boolean | ThunkOptions;
  13. immutableCheck?: boolean | ImmutableStateInvariantMiddlewareOptions;
  14. serializableCheck?: boolean | SerializableStateInvariantMiddlewareOptions;
  15. actionCreatorCheck?: boolean | ActionCreatorInvariantMiddlewareOptions;
  16. }
  17. export declare type ThunkMiddlewareFor<S, O extends GetDefaultMiddlewareOptions = {}> = O extends {
  18. thunk: false;
  19. } ? never : O extends {
  20. thunk: {
  21. extraArgument: infer E;
  22. };
  23. } ? ThunkMiddleware<S, AnyAction, E> : ThunkMiddleware<S, AnyAction>;
  24. export declare type CurriedGetDefaultMiddleware<S = any> = <O extends Partial<GetDefaultMiddlewareOptions> = {
  25. thunk: true;
  26. immutableCheck: true;
  27. serializableCheck: true;
  28. actionCreatorCheck: true;
  29. }>(options?: O) => MiddlewareArray<ExcludeFromTuple<[ThunkMiddlewareFor<S, O>], never>>;
  30. export declare function curryGetDefaultMiddleware<S = any>(): CurriedGetDefaultMiddleware<S>;
  31. /**
  32. * Returns any array containing the default middleware installed by
  33. * `configureStore()`. Useful if you want to configure your store with a custom
  34. * `middleware` array but still keep the default set.
  35. *
  36. * @return The default middleware used by `configureStore()`.
  37. *
  38. * @public
  39. *
  40. * @deprecated Prefer to use the callback notation for the `middleware` option in `configureStore`
  41. * to access a pre-typed `getDefaultMiddleware` instead.
  42. */
  43. export declare function getDefaultMiddleware<S = any, O extends Partial<GetDefaultMiddlewareOptions> = {
  44. thunk: true;
  45. immutableCheck: true;
  46. serializableCheck: true;
  47. actionCreatorCheck: true;
  48. }>(options?: O): MiddlewareArray<ExcludeFromTuple<[ThunkMiddlewareFor<S, O>], never>>;
  49. export {};