Skip to content

Commit 8c8b382

Browse files
authored
Merge pull request #3363 from EskiMojo14/unknown-action
2 parents 37b3723 + 28bb5ea commit 8c8b382

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+388
-359
lines changed

docs/api/configureStore.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ to the store setup for a better development experience.
2020

2121
interface ConfigureStoreOptions<
2222
S = any,
23-
A extends Action = AnyAction,
23+
A extends Action = UnknownAction,
2424
M extends Middlewares<S> = Middlewares<S>
2525
E extends Enhancers = Enhancers
2626
> {
@@ -64,7 +64,7 @@ interface ConfigureStoreOptions<
6464
enhancers?: (getDefaultEnhancers: GetDefaultEnhancers<M>) => E | E
6565
}
6666

67-
function configureStore<S = any, A extends Action = AnyAction>(
67+
function configureStore<S = any, A extends Action = UnknownAction>(
6868
options: ConfigureStoreOptions<S, A>
6969
): EnhancedStore<S, A>
7070
```

docs/api/createDynamicMiddleware.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The "dynamic middleware instance" returned from `createDynamicMiddleware` is an
8080
```ts no-transpile
8181
export type DynamicMiddlewareInstance<
8282
State = unknown,
83-
Dispatch extends ReduxDispatch<AnyAction> = ReduxDispatch<AnyAction>
83+
Dispatch extends ReduxDispatch<UnknownAction> = ReduxDispatch<UnknownAction>
8484
> = {
8585
middleware: DynamicMiddleware<State, Dispatch>
8686
addMiddleware: AddMiddleware<State, Dispatch>
@@ -131,7 +131,7 @@ _These depend on having `react-redux` installed._
131131
```ts no-transpile
132132
interface ReactDynamicMiddlewareInstance<
133133
State = any,
134-
Dispatch extends ReduxDispatch<AnyAction> = ReduxDispatch<AnyAction>
134+
Dispatch extends ReduxDispatch<UnknownAction> = ReduxDispatch<UnknownAction>
135135
> extends DynamicMiddlewareInstance<State, Dispatch> {
136136
createDispatchWithMiddlewareHook: CreateDispatchWithMiddlewareHook<
137137
State,

docs/api/createListenerMiddleware.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ The "listener middleware instance" returned from `createListenerMiddleware` is a
120120
```ts no-transpile
121121
interface ListenerMiddlewareInstance<
122122
State = unknown,
123-
Dispatch extends ThunkDispatch<State, unknown, AnyAction> = ThunkDispatch<
123+
Dispatch extends ThunkDispatch<State, unknown, UnknownAction> = ThunkDispatch<
124124
State,
125125
unknown,
126-
AnyAction
126+
UnknownAction
127127
>,
128128
ExtraArgument = unknown
129129
> {
@@ -181,7 +181,7 @@ interface AddListenerOptions {
181181
effect: (action: Action, listenerApi: ListenerApi) => void | Promise<void>
182182
}
183183

184-
type ListenerPredicate<Action extends AnyAction, State> = (
184+
type ListenerPredicate<Action extends ReduxAction, State> = (
185185
action: Action,
186186
currentState?: State,
187187
originalState?: State
@@ -321,7 +321,7 @@ The `listenerApi` object is the second argument to each listener callback. It co
321321
```ts no-transpile
322322
export interface ListenerEffectAPI<
323323
State,
324-
Dispatch extends ReduxDispatch<AnyAction>,
324+
Dispatch extends ReduxDispatch<UnknownAction>,
325325
ExtraArgument = unknown
326326
> extends MiddlewareAPI<Dispatch, State> {
327327
// NOTE: MiddlewareAPI contains `dispatch` and `getState` already
@@ -572,12 +572,12 @@ Listeners can use the `condition` and `take` methods in `listenerApi` to wait un
572572
The signatures are:
573573

574574
```ts no-transpile
575-
type ConditionFunction<Action extends AnyAction, State> = (
575+
type ConditionFunction<Action extends ReduxAction, State> = (
576576
predicate: ListenerPredicate<Action, State> | (() => boolean),
577577
timeout?: number
578578
) => Promise<boolean>
579579

580-
type TakeFunction<Action extends AnyAction, State> = (
580+
type TakeFunction<Action extends ReduxAction, State> = (
581581
predicate: ListenerPredicate<Action, State> | (() => boolean),
582582
timeout?: number
583583
) => Promise<[Action, State, State] | null>

docs/api/matching-utilities.mdx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ A higher-order function that returns a type guard function that may be used to c
4949

5050
```ts title="isAsyncThunkAction usage"
5151
import { isAsyncThunkAction } from '@reduxjs/toolkit'
52-
import type { AnyAction } from '@reduxjs/toolkit'
52+
import type { UnknownAction } from '@reduxjs/toolkit'
5353
import { requestThunk1, requestThunk2 } from '@virtual/matchers'
5454

5555
const isARequestAction = isAsyncThunkAction(requestThunk1, requestThunk2)
5656

57-
function handleRequestAction(action: AnyAction) {
57+
function handleRequestAction(action: UnknownAction) {
5858
if (isARequestAction(action)) {
5959
// action is an action dispatched by either `requestThunk1` or `requestThunk2`
6060
}
@@ -67,12 +67,12 @@ A higher-order function that returns a type guard function that may be used to c
6767

6868
```ts title="isPending usage"
6969
import { isPending } from '@reduxjs/toolkit'
70-
import type { AnyAction } from '@reduxjs/toolkit'
70+
import type { UnknownAction } from '@reduxjs/toolkit'
7171
import { requestThunk1, requestThunk2 } from '@virtual/matchers'
7272

7373
const isAPendingAction = isPending(requestThunk1, requestThunk2)
7474

75-
function handlePendingAction(action: AnyAction) {
75+
function handlePendingAction(action: UnknownAction) {
7676
if (isAPendingAction(action)) {
7777
// action is a pending action dispatched by either `requestThunk1` or `requestThunk2`
7878
}
@@ -85,12 +85,12 @@ A higher-order function that returns a type guard function that may be used to c
8585

8686
```ts title="isFulfilled usage"
8787
import { isFulfilled } from '@reduxjs/toolkit'
88-
import type { AnyAction } from '@reduxjs/toolkit'
88+
import type { UnknownAction } from '@reduxjs/toolkit'
8989
import { requestThunk1, requestThunk2 } from '@virtual/matchers'
9090

9191
const isAFulfilledAction = isFulfilled(requestThunk1, requestThunk2)
9292

93-
function handleFulfilledAction(action: AnyAction) {
93+
function handleFulfilledAction(action: UnknownAction) {
9494
if (isAFulfilledAction(action)) {
9595
// action is a fulfilled action dispatched by either `requestThunk1` or `requestThunk2`
9696
}
@@ -103,12 +103,12 @@ A higher-order function that returns a type guard function that may be used to c
103103

104104
```ts title="isRejected usage"
105105
import { isRejected } from '@reduxjs/toolkit'
106-
import type { AnyAction } from '@reduxjs/toolkit'
106+
import type { UnknownAction } from '@reduxjs/toolkit'
107107
import { requestThunk1, requestThunk2 } from '@virtual/matchers'
108108

109109
const isARejectedAction = isRejected(requestThunk1, requestThunk2)
110110

111-
function handleRejectedAction(action: AnyAction) {
111+
function handleRejectedAction(action: UnknownAction) {
112112
if (isARejectedAction(action)) {
113113
// action is a rejected action dispatched by either `requestThunk1` or `requestThunk2`
114114
}
@@ -121,15 +121,15 @@ A higher-order function that returns a type guard function that may be used to c
121121

122122
```ts title="isRejectedWithValue usage"
123123
import { isRejectedWithValue } from '@reduxjs/toolkit'
124-
import type { AnyAction } from '@reduxjs/toolkit'
124+
import type { UnknownAction } from '@reduxjs/toolkit'
125125
import { requestThunk1, requestThunk2 } from '@virtual/matchers'
126126

127127
const isARejectedWithValueAction = isRejectedWithValue(
128128
requestThunk1,
129129
requestThunk2
130130
)
131131

132-
function handleRejectedWithValueAction(action: AnyAction) {
132+
function handleRejectedWithValueAction(action: UnknownAction) {
133133
if (isARejectedWithValueAction(action)) {
134134
// action is a rejected action dispatched by either `requestThunk1` or `requestThunk2`
135135
// 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
145145
First, let's examine an unnecessarily complex example:
146146

147147
```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'
152149
import type { PayloadAction } from '@reduxjs/toolkit'
153150

154151
interface Data {

docs/rtk-query/api/createApi.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const { useGetPokemonByNameQuery } = pokemonApi
5757
baseQuery(args: InternalQueryArgs, api: BaseQueryApi, extraOptions?: DefinitionExtraOptions): any;
5858
endpoints(build: EndpointBuilder<InternalQueryArgs, TagTypes>): Definitions;
5959
extractRehydrationInfo?: (
60-
action: AnyAction,
60+
action: UnknownAction,
6161
{
6262
reducerPath,
6363
}: {
@@ -88,7 +88,7 @@ export const { useGetPokemonByNameQuery } = pokemonApi
8888
- `dispatch` - The `store.dispatch` method for the corresponding Redux store
8989
- `getState` - A function that may be called to access the current store state
9090
- `extra` - Provided as thunk.extraArgument to the configureStore getDefaultMiddleware option.
91-
- `endpoint` - The name of the endpoint.
91+
- `endpoint` - The name of the endpoint.
9292
- `type` - Type of request (`query` or `mutation`).
9393
- `forced` - Indicates if a query has been forced.
9494
- `extraOptions` - The value of the optional `extraOptions` property provided for a given endpoint

docs/rtk-query/api/created-api/api-slice-utils.mdx

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const updateQueryData = (
3030
endpointName: string,
3131
args: any,
3232
updateRecipe: (draft: Draft<CachedState>) => void
33-
) => ThunkAction<PatchCollection, PartialState, any, AnyAction>;
33+
) => ThunkAction<PatchCollection, PartialState, any, UnknownAction>;
3434

3535
interface PatchCollection {
3636
patches: Patch[];
@@ -119,7 +119,7 @@ const upsertQueryData = <T>(
119119
endpointName: string,
120120
args: any,
121121
newEntryData: T
122-
) => ThunkAction<Promise<CacheEntry<T>>, PartialState, any, AnyAction>;
122+
) => ThunkAction<Promise<CacheEntry<T>>, PartialState, any, UnknownAction>;
123123
```
124124

125125
- **Parameters**
@@ -156,7 +156,7 @@ const patchQueryData = (
156156
endpointName: string,
157157
args: any
158158
patches: Patch[]
159-
) => ThunkAction<void, PartialState, any, AnyAction>;
159+
) => ThunkAction<void, PartialState, any, UnknownAction>;
160160
```
161161

162162
- **Parameters**
@@ -203,7 +203,7 @@ const prefetch = (
203203
endpointName: string,
204204
arg: any,
205205
options: PrefetchOptions
206-
) => ThunkAction<void, any, any, AnyAction>;
206+
) => ThunkAction<void, any, any, UnknownAction>;
207207
```
208208

209209
- **Parameters**
@@ -229,42 +229,44 @@ dispatch(api.util.prefetch('getPosts', undefined, { force: true }))
229229
```
230230

231231
### `selectInvalidatedBy`
232-
232+
233233
#### Signature
234-
234+
235235
```ts no-transpile
236-
function selectInvalidatedBy(
237-
state: RootState,
238-
tags: ReadonlyArray<TagDescription<string>>
239-
): Array<{
240-
endpointName: string
241-
originalArgs: any
242-
queryCacheKey: QueryCacheKey
243-
}>
236+
function selectInvalidatedBy(
237+
state: RootState,
238+
tags: ReadonlyArray<TagDescription<string>>
239+
): Array<{
240+
endpointName: string
241+
originalArgs: any
242+
queryCacheKey: QueryCacheKey
243+
}>
244244
```
245-
245+
246246
- **Parameters**
247247
- `state`: the root state
248248
- `tags`: a readonly array of invalidated tags, where the provided `TagDescription` is one of the strings provided to the [`tagTypes`](../createApi.mdx#tagtypes) property of the api. e.g.
249249
- `[TagType]`
250250
- `[{ type: TagType }]`
251251
- `[{ type: TagType, id: number | string }]`
252-
252+
253253
#### Description
254-
254+
255255
A function that can select query parameters to be invalidated.
256-
256+
257257
The function accepts two arguments
258-
- the root state and
259-
- the cache tags to be invalidated.
260-
258+
259+
- the root state and
260+
- the cache tags to be invalidated.
261+
261262
It returns an array that contains
262-
- the endpoint name,
263-
- the original args and
264-
- the queryCacheKey.
265-
263+
264+
- the endpoint name,
265+
- the original args and
266+
- the queryCacheKey.
267+
266268
#### Example
267-
269+
268270
```ts no-transpile
269271
dispatch(api.util.selectInvalidatedBy(state, ['Post']))
270272
dispatch(api.util.selectInvalidatedBy(state, [{ type: 'Post', id: 1 }]))

docs/rtk-query/api/created-api/endpoints.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ type InitiateRequestThunk = StartQueryActionCreator | StartMutationActionCreator
3333
type StartQueryActionCreator = (
3434
arg:any,
3535
options?: StartQueryActionCreatorOptions
36-
) => ThunkAction<QueryActionCreatorResult, any, any, AnyAction>;
36+
) => ThunkAction<QueryActionCreatorResult, any, any, UnknownAction>;
3737

3838
type StartMutationActionCreator<D extends MutationDefinition<any, any, any, any>> = (
3939
arg: any
4040
options?: StartMutationActionCreatorOptions
41-
) => ThunkAction<MutationActionCreatorResult<D>, any, any, AnyAction>;
41+
) => ThunkAction<MutationActionCreatorResult<D>, any, any, UnknownAction>;
4242

4343
type SubscriptionOptions = {
4444
/**

docs/usage/usage-with-typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ As the first `matcher` argument to `builder.addMatcher`, a [type predicate](http
252252
As a result, the `action` argument for the second `reducer` argument can be inferred by TypeScript:
253253

254254
```ts
255-
function isNumberValueAction(action: AnyAction): action is PayloadAction<{ value: number }> {
255+
function isNumberValueAction(action: UnknownAction): action is PayloadAction<{ value: number }> {
256256
return typeof action.payload.value === 'number'
257257
}
258258

examples/action-listener/counter/src/services/counter/listeners.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { counterActions, counterSelectors } from './slice'
22
import {
3-
AnyAction,
3+
UnknownAction,
44
isAllOf,
55
isAnyOf,
66
PayloadAction,
@@ -11,7 +11,7 @@ import type { AppListenerEffectAPI, AppStartListening } from '../../store'
1111
function shouldStopAsyncTasksOf(id: string) {
1212
return isAllOf(
1313
isAnyOf(counterActions.cancelAsyncUpdates, counterActions.removeCounter),
14-
(action: AnyAction): action is PayloadAction<string> =>
14+
(action: UnknownAction): action is PayloadAction<string> =>
1515
action?.payload === id
1616
)
1717
}

packages/toolkit/etc/redux-toolkit.api.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
```ts
66
import type { Action } from 'redux'
77
import type { ActionCreator } from 'redux'
8-
import type { AnyAction } from 'redux'
8+
import type { UnknownAction } from 'redux'
99
import type { CombinedState } from 'redux'
1010
import { default as createNextState } from 'immer'
1111
import { createSelector } from 'reselect'
@@ -85,10 +85,10 @@ export interface ActionReducerMapBuilder<State> {
8585
type: Type,
8686
reducer: CaseReducer<State, A>
8787
): ActionReducerMapBuilder<State>
88-
addDefaultCase(reducer: CaseReducer<State, AnyAction>): {}
88+
addDefaultCase(reducer: CaseReducer<State, UnknownAction>): {}
8989
addMatcher<A>(
9090
matcher: TypeGuard<A> | ((action: any) => boolean),
91-
reducer: CaseReducer<State, A extends AnyAction ? A : A & AnyAction>
91+
reducer: CaseReducer<State, A extends Action ? A : A & Action>
9292
): Omit<ActionReducerMapBuilder<State>, 'addCase'>
9393
}
9494

@@ -191,7 +191,7 @@ export type AsyncThunkPayloadCreatorReturnValue<
191191
>
192192

193193
// @public
194-
export type CaseReducer<S = any, A extends Action = AnyAction> = (
194+
export type CaseReducer<S = any, A extends Action = UnknownAction> = (
195195
state: Draft<S>,
196196
action: A
197197
) => S | void | Draft<S>
@@ -227,14 +227,14 @@ export type ConfigureEnhancersCallback = (
227227
// @public
228228
export function configureStore<
229229
S = any,
230-
A extends Action = AnyAction,
230+
A extends Action = UnknownAction,
231231
M extends Middlewares<S> = [ThunkMiddlewareFor<S>]
232232
>(options: ConfigureStoreOptions<S, A, M>): EnhancedStore<S, A, M>
233233

234234
// @public
235235
export interface ConfigureStoreOptions<
236236
S = any,
237-
A extends Action = AnyAction,
237+
A extends Action = UnknownAction,
238238
M extends Middlewares<S> = Middlewares<S>
239239
> {
240240
devTools?: boolean | EnhancerOptions
@@ -352,7 +352,7 @@ export { Draft }
352352
// @public
353353
export interface EnhancedStore<
354354
S = any,
355-
A extends Action = AnyAction,
355+
A extends Action = UnknownAction,
356356
M extends Middlewares<S> = Middlewares<S>
357357
> extends Store<S, A> {
358358
dispatch: Dispatch<A> & DispatchForMiddlewares<M>

0 commit comments

Comments
 (0)