@@ -49,12 +49,12 @@ A higher-order function that returns a type guard function that may be used to c
49
49
50
50
``` ts title="isAsyncThunkAction usage"
51
51
import { isAsyncThunkAction } from ' @reduxjs/toolkit'
52
- import type { AnyAction } from ' @reduxjs/toolkit'
52
+ import type { UnknownAction } from ' @reduxjs/toolkit'
53
53
import { requestThunk1 , requestThunk2 } from ' @virtual/matchers'
54
54
55
55
const isARequestAction = isAsyncThunkAction (requestThunk1 , requestThunk2 )
56
56
57
- function handleRequestAction(action : AnyAction ) {
57
+ function handleRequestAction(action : UnknownAction ) {
58
58
if (isARequestAction (action )) {
59
59
// action is an action dispatched by either `requestThunk1` or `requestThunk2`
60
60
}
@@ -67,12 +67,12 @@ A higher-order function that returns a type guard function that may be used to c
67
67
68
68
``` ts title="isPending usage"
69
69
import { isPending } from ' @reduxjs/toolkit'
70
- import type { AnyAction } from ' @reduxjs/toolkit'
70
+ import type { UnknownAction } from ' @reduxjs/toolkit'
71
71
import { requestThunk1 , requestThunk2 } from ' @virtual/matchers'
72
72
73
73
const isAPendingAction = isPending (requestThunk1 , requestThunk2 )
74
74
75
- function handlePendingAction(action : AnyAction ) {
75
+ function handlePendingAction(action : UnknownAction ) {
76
76
if (isAPendingAction (action )) {
77
77
// action is a pending action dispatched by either `requestThunk1` or `requestThunk2`
78
78
}
@@ -85,12 +85,12 @@ A higher-order function that returns a type guard function that may be used to c
85
85
86
86
``` ts title="isFulfilled usage"
87
87
import { isFulfilled } from ' @reduxjs/toolkit'
88
- import type { AnyAction } from ' @reduxjs/toolkit'
88
+ import type { UnknownAction } from ' @reduxjs/toolkit'
89
89
import { requestThunk1 , requestThunk2 } from ' @virtual/matchers'
90
90
91
91
const isAFulfilledAction = isFulfilled (requestThunk1 , requestThunk2 )
92
92
93
- function handleFulfilledAction(action : AnyAction ) {
93
+ function handleFulfilledAction(action : UnknownAction ) {
94
94
if (isAFulfilledAction (action )) {
95
95
// action is a fulfilled action dispatched by either `requestThunk1` or `requestThunk2`
96
96
}
@@ -103,12 +103,12 @@ A higher-order function that returns a type guard function that may be used to c
103
103
104
104
``` ts title="isRejected usage"
105
105
import { isRejected } from ' @reduxjs/toolkit'
106
- import type { AnyAction } from ' @reduxjs/toolkit'
106
+ import type { UnknownAction } from ' @reduxjs/toolkit'
107
107
import { requestThunk1 , requestThunk2 } from ' @virtual/matchers'
108
108
109
109
const isARejectedAction = isRejected (requestThunk1 , requestThunk2 )
110
110
111
- function handleRejectedAction(action : AnyAction ) {
111
+ function handleRejectedAction(action : UnknownAction ) {
112
112
if (isARejectedAction (action )) {
113
113
// action is a rejected action dispatched by either `requestThunk1` or `requestThunk2`
114
114
}
@@ -121,15 +121,15 @@ A higher-order function that returns a type guard function that may be used to c
121
121
122
122
``` ts title="isRejectedWithValue usage"
123
123
import { isRejectedWithValue } from ' @reduxjs/toolkit'
124
- import type { AnyAction } from ' @reduxjs/toolkit'
124
+ import type { UnknownAction } from ' @reduxjs/toolkit'
125
125
import { requestThunk1 , requestThunk2 } from ' @virtual/matchers'
126
126
127
127
const isARejectedWithValueAction = isRejectedWithValue (
128
128
requestThunk1 ,
129
129
requestThunk2
130
130
)
131
131
132
- function handleRejectedWithValueAction(action : AnyAction ) {
132
+ function handleRejectedWithValueAction(action : UnknownAction ) {
133
133
if (isARejectedWithValueAction (action )) {
134
134
// action is a rejected action dispatched by either `requestThunk1` or `requestThunk2`
135
135
// where rejectWithValue was used
@@ -145,10 +145,7 @@ we're able to easily use the same matcher for several cases in a type-safe manne
145
145
First, let's examine an unnecessarily complex example:
146
146
147
147
``` ts title="Example without using a matcher utility"
148
- import {
149
- createAsyncThunk ,
150
- createReducer ,
151
- } from ' @reduxjs/toolkit'
148
+ import { createAsyncThunk , createReducer } from ' @reduxjs/toolkit'
152
149
import type { PayloadAction } from ' @reduxjs/toolkit'
153
150
154
151
interface Data {
0 commit comments