matchers.d.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import type { ActionFromMatcher, Matcher, UnionToIntersection } from './tsHelpers';
  2. import type { AsyncThunk, AsyncThunkFulfilledActionCreator, AsyncThunkPendingActionCreator, AsyncThunkRejectedActionCreator } from './createAsyncThunk';
  3. /** @public */
  4. export declare type ActionMatchingAnyOf<Matchers extends [...Matcher<any>[]]> = ActionFromMatcher<Matchers[number]>;
  5. /** @public */
  6. export declare type ActionMatchingAllOf<Matchers extends [...Matcher<any>[]]> = UnionToIntersection<ActionMatchingAnyOf<Matchers>>;
  7. /**
  8. * A higher-order function that returns a function that may be used to check
  9. * whether an action matches any one of the supplied type guards or action
  10. * creators.
  11. *
  12. * @param matchers The type guards or action creators to match against.
  13. *
  14. * @public
  15. */
  16. export declare function isAnyOf<Matchers extends [...Matcher<any>[]]>(...matchers: Matchers): (action: any) => action is ActionFromMatcher<Matchers[number]>;
  17. /**
  18. * A higher-order function that returns a function that may be used to check
  19. * whether an action matches all of the supplied type guards or action
  20. * creators.
  21. *
  22. * @param matchers The type guards or action creators to match against.
  23. *
  24. * @public
  25. */
  26. export declare function isAllOf<Matchers extends [...Matcher<any>[]]>(...matchers: Matchers): (action: any) => action is UnionToIntersection<ActionFromMatcher<Matchers[number]>>;
  27. /**
  28. * @param action A redux action
  29. * @param validStatus An array of valid meta.requestStatus values
  30. *
  31. * @internal
  32. */
  33. export declare function hasExpectedRequestMetadata(action: any, validStatus: readonly string[]): boolean;
  34. export declare type UnknownAsyncThunkPendingAction = ReturnType<AsyncThunkPendingActionCreator<unknown>>;
  35. export declare type PendingActionFromAsyncThunk<T extends AnyAsyncThunk> = ActionFromMatcher<T['pending']>;
  36. /**
  37. * A higher-order function that returns a function that may be used to check
  38. * whether an action was created by an async thunk action creator, and that
  39. * the action is pending.
  40. *
  41. * @public
  42. */
  43. export declare function isPending(): (action: any) => action is UnknownAsyncThunkPendingAction;
  44. /**
  45. * A higher-order function that returns a function that may be used to check
  46. * whether an action belongs to one of the provided async thunk action creators,
  47. * and that the action is pending.
  48. *
  49. * @param asyncThunks (optional) The async thunk action creators to match against.
  50. *
  51. * @public
  52. */
  53. export declare function isPending<AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]>(...asyncThunks: AsyncThunks): (action: any) => action is PendingActionFromAsyncThunk<AsyncThunks[number]>;
  54. /**
  55. * Tests if `action` is a pending thunk action
  56. * @public
  57. */
  58. export declare function isPending(action: any): action is UnknownAsyncThunkPendingAction;
  59. export declare type UnknownAsyncThunkRejectedAction = ReturnType<AsyncThunkRejectedActionCreator<unknown, unknown>>;
  60. export declare type RejectedActionFromAsyncThunk<T extends AnyAsyncThunk> = ActionFromMatcher<T['rejected']>;
  61. /**
  62. * A higher-order function that returns a function that may be used to check
  63. * whether an action was created by an async thunk action creator, and that
  64. * the action is rejected.
  65. *
  66. * @public
  67. */
  68. export declare function isRejected(): (action: any) => action is UnknownAsyncThunkRejectedAction;
  69. /**
  70. * A higher-order function that returns a function that may be used to check
  71. * whether an action belongs to one of the provided async thunk action creators,
  72. * and that the action is rejected.
  73. *
  74. * @param asyncThunks (optional) The async thunk action creators to match against.
  75. *
  76. * @public
  77. */
  78. export declare function isRejected<AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]>(...asyncThunks: AsyncThunks): (action: any) => action is RejectedActionFromAsyncThunk<AsyncThunks[number]>;
  79. /**
  80. * Tests if `action` is a rejected thunk action
  81. * @public
  82. */
  83. export declare function isRejected(action: any): action is UnknownAsyncThunkRejectedAction;
  84. export declare type UnknownAsyncThunkRejectedWithValueAction = ReturnType<AsyncThunkRejectedActionCreator<unknown, unknown>>;
  85. export declare type RejectedWithValueActionFromAsyncThunk<T extends AnyAsyncThunk> = ActionFromMatcher<T['rejected']> & (T extends AsyncThunk<any, any, {
  86. rejectValue: infer RejectedValue;
  87. }> ? {
  88. payload: RejectedValue;
  89. } : unknown);
  90. /**
  91. * A higher-order function that returns a function that may be used to check
  92. * whether an action was created by an async thunk action creator, and that
  93. * the action is rejected with value.
  94. *
  95. * @public
  96. */
  97. export declare function isRejectedWithValue(): (action: any) => action is UnknownAsyncThunkRejectedAction;
  98. /**
  99. * A higher-order function that returns a function that may be used to check
  100. * whether an action belongs to one of the provided async thunk action creators,
  101. * and that the action is rejected with value.
  102. *
  103. * @param asyncThunks (optional) The async thunk action creators to match against.
  104. *
  105. * @public
  106. */
  107. export declare function isRejectedWithValue<AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]>(...asyncThunks: AsyncThunks): (action: any) => action is RejectedWithValueActionFromAsyncThunk<AsyncThunks[number]>;
  108. /**
  109. * Tests if `action` is a rejected thunk action with value
  110. * @public
  111. */
  112. export declare function isRejectedWithValue(action: any): action is UnknownAsyncThunkRejectedAction;
  113. export declare type UnknownAsyncThunkFulfilledAction = ReturnType<AsyncThunkFulfilledActionCreator<unknown, unknown>>;
  114. export declare type FulfilledActionFromAsyncThunk<T extends AnyAsyncThunk> = ActionFromMatcher<T['fulfilled']>;
  115. /**
  116. * A higher-order function that returns a function that may be used to check
  117. * whether an action was created by an async thunk action creator, and that
  118. * the action is fulfilled.
  119. *
  120. * @public
  121. */
  122. export declare function isFulfilled(): (action: any) => action is UnknownAsyncThunkFulfilledAction;
  123. /**
  124. * A higher-order function that returns a function that may be used to check
  125. * whether an action belongs to one of the provided async thunk action creators,
  126. * and that the action is fulfilled.
  127. *
  128. * @param asyncThunks (optional) The async thunk action creators to match against.
  129. *
  130. * @public
  131. */
  132. export declare function isFulfilled<AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]>(...asyncThunks: AsyncThunks): (action: any) => action is FulfilledActionFromAsyncThunk<AsyncThunks[number]>;
  133. /**
  134. * Tests if `action` is a fulfilled thunk action
  135. * @public
  136. */
  137. export declare function isFulfilled(action: any): action is UnknownAsyncThunkFulfilledAction;
  138. export declare type UnknownAsyncThunkAction = UnknownAsyncThunkPendingAction | UnknownAsyncThunkRejectedAction | UnknownAsyncThunkFulfilledAction;
  139. export declare type AnyAsyncThunk = {
  140. pending: {
  141. match: (action: any) => action is any;
  142. };
  143. fulfilled: {
  144. match: (action: any) => action is any;
  145. };
  146. rejected: {
  147. match: (action: any) => action is any;
  148. };
  149. };
  150. export declare type ActionsFromAsyncThunk<T extends AnyAsyncThunk> = ActionFromMatcher<T['pending']> | ActionFromMatcher<T['fulfilled']> | ActionFromMatcher<T['rejected']>;
  151. /**
  152. * A higher-order function that returns a function that may be used to check
  153. * whether an action was created by an async thunk action creator.
  154. *
  155. * @public
  156. */
  157. export declare function isAsyncThunkAction(): (action: any) => action is UnknownAsyncThunkAction;
  158. /**
  159. * A higher-order function that returns a function that may be used to check
  160. * whether an action belongs to one of the provided async thunk action creators.
  161. *
  162. * @param asyncThunks (optional) The async thunk action creators to match against.
  163. *
  164. * @public
  165. */
  166. export declare function isAsyncThunkAction<AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]>(...asyncThunks: AsyncThunks): (action: any) => action is ActionsFromAsyncThunk<AsyncThunks[number]>;
  167. /**
  168. * Tests if `action` is a thunk action
  169. * @public
  170. */
  171. export declare function isAsyncThunkAction(action: any): action is UnknownAsyncThunkAction;