Skip to content

Commit a77d8c9

Browse files
committed
Use Redux 5 action types
1 parent a5a2074 commit a77d8c9

File tree

9 files changed

+29
-26
lines changed

9 files changed

+29
-26
lines changed

src/components/Context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as React from 'react'
22
import type { Context } from 'react'
3-
import type { Action, AnyAction, Store } from 'redux'
3+
import type { Action, Store, UnknownAction } from 'redux'
44
import type { Subscription } from '../utils/Subscription'
55
import type { CheckFrequency } from '../hooks/useSelector'
66

77
export interface ReactReduxContextValue<
88
SS = any,
9-
A extends Action = AnyAction
9+
A extends Action<string> = UnknownAction
1010
> {
1111
store: Store<SS, A>
1212
subscription: Subscription

src/components/Provider.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import type { ReactReduxContextValue } from './Context'
44
import { ReactReduxContext } from './Context'
55
import { createSubscription } from '../utils/Subscription'
66
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
7-
import type { Action, AnyAction, Store } from 'redux'
7+
import type { Action, Store, UnknownAction } from 'redux'
88
import type { CheckFrequency } from '../hooks/useSelector'
99

10-
export interface ProviderProps<A extends Action = AnyAction, S = unknown> {
10+
export interface ProviderProps<
11+
A extends Action<string> = UnknownAction,
12+
S = unknown
13+
> {
1114
/**
1215
* The single Redux store in your application.
1316
*/
@@ -34,7 +37,7 @@ export interface ProviderProps<A extends Action = AnyAction, S = unknown> {
3437
children: ReactNode
3538
}
3639

37-
function Provider<A extends Action = AnyAction, S = unknown>({
40+
function Provider<A extends Action<string> = UnknownAction, S = unknown>({
3841
store,
3942
context,
4043
children,

src/connect/invalidArgFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Action, Dispatch } from 'redux'
22

33
export function createInvalidArgFactory(arg: unknown, name: string) {
44
return (
5-
dispatch: Dispatch<Action<unknown>>,
5+
dispatch: Dispatch<Action<string>>,
66
options: { readonly wrappedComponentName: string }
77
) => {
88
throw new Error(

src/connect/mapDispatchToProps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ export function mapDispatchToPropsFactory<TDispatchProps, TOwnProps>(
1010
| undefined
1111
) {
1212
return mapDispatchToProps && typeof mapDispatchToProps === 'object'
13-
? wrapMapToPropsConstant((dispatch: Dispatch<Action<unknown>>) =>
13+
? wrapMapToPropsConstant((dispatch: Dispatch<Action<string>>) =>
1414
// @ts-ignore
1515
bindActionCreators(mapDispatchToProps, dispatch)
1616
)
1717
: !mapDispatchToProps
18-
? wrapMapToPropsConstant((dispatch: Dispatch<Action<unknown>>) => ({
18+
? wrapMapToPropsConstant((dispatch: Dispatch<Action<string>>) => ({
1919
dispatch,
2020
}))
2121
: typeof mapDispatchToProps === 'function'

src/connect/mergeProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function wrapMergePropsFunc<
2626
>(
2727
mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>
2828
): (
29-
dispatch: Dispatch<Action<unknown>>,
29+
dispatch: Dispatch<Action<string>>,
3030
options: {
3131
readonly displayName: string
3232
readonly areMergedPropsEqual: EqualityFn<TMergedProps>

src/connect/selectorFactory.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import verifySubselectors from './verifySubselectors'
44
import type { EqualityFn, ExtendedEqualityFn } from '../types'
55

66
export type SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> = (
7-
dispatch: Dispatch<Action<unknown>>,
7+
dispatch: Dispatch<Action<string>>,
88
factoryOptions: TFactoryOptions
99
) => Selector<S, TProps, TOwnProps>
1010

@@ -31,7 +31,7 @@ export type MapStateToPropsParam<TStateProps, TOwnProps, State> =
3131
| undefined
3232

3333
export type MapDispatchToPropsFunction<TDispatchProps, TOwnProps> = (
34-
dispatch: Dispatch<Action<unknown>>,
34+
dispatch: Dispatch<Action<string>>,
3535
ownProps: TOwnProps
3636
) => TDispatchProps
3737

@@ -40,7 +40,7 @@ export type MapDispatchToProps<TDispatchProps, TOwnProps> =
4040
| TDispatchProps
4141

4242
export type MapDispatchToPropsFactory<TDispatchProps, TOwnProps> = (
43-
dispatch: Dispatch<Action<unknown>>,
43+
dispatch: Dispatch<Action<string>>,
4444
ownProps: TOwnProps
4545
) => MapDispatchToPropsFunction<TDispatchProps, TOwnProps>
4646

@@ -74,7 +74,7 @@ export function pureFinalPropsSelectorFactory<
7474
mapStateToProps: WrappedMapStateToProps<TStateProps, TOwnProps, State>,
7575
mapDispatchToProps: WrappedMapDispatchToProps<TDispatchProps, TOwnProps>,
7676
mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>,
77-
dispatch: Dispatch<Action<unknown>>,
77+
dispatch: Dispatch<Action<string>>,
7878
{
7979
areStatesEqual,
8080
areOwnPropsEqual,
@@ -163,7 +163,7 @@ interface WrappedMapStateToProps<TStateProps, TOwnProps, State> {
163163
}
164164

165165
interface WrappedMapDispatchToProps<TDispatchProps, TOwnProps> {
166-
(dispatch: Dispatch<Action<unknown>>, ownProps: TOwnProps): TDispatchProps
166+
(dispatch: Dispatch<Action<string>>, ownProps: TOwnProps): TDispatchProps
167167
readonly dependsOnOwnProps: boolean
168168
}
169169

@@ -184,15 +184,15 @@ export interface SelectorFactoryOptions<
184184
State
185185
> extends InitOptions<TStateProps, TOwnProps, TMergedProps, State> {
186186
readonly initMapStateToProps: (
187-
dispatch: Dispatch<Action<unknown>>,
187+
dispatch: Dispatch<Action<string>>,
188188
options: InitOptions<TStateProps, TOwnProps, TMergedProps, State>
189189
) => WrappedMapStateToProps<TStateProps, TOwnProps, State>
190190
readonly initMapDispatchToProps: (
191-
dispatch: Dispatch<Action<unknown>>,
191+
dispatch: Dispatch<Action<string>>,
192192
options: InitOptions<TStateProps, TOwnProps, TMergedProps, State>
193193
) => WrappedMapDispatchToProps<TDispatchProps, TOwnProps>
194194
readonly initMergeProps: (
195-
dispatch: Dispatch<Action<unknown>>,
195+
dispatch: Dispatch<Action<string>>,
196196
options: InitOptions<TStateProps, TOwnProps, TMergedProps, State>
197197
) => MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>
198198
}
@@ -210,7 +210,7 @@ export default function finalPropsSelectorFactory<
210210
TMergedProps,
211211
State
212212
>(
213-
dispatch: Dispatch<Action<unknown>>,
213+
dispatch: Dispatch<Action<string>>,
214214
{
215215
initMapStateToProps,
216216
initMapDispatchToProps,

src/hooks/useDispatch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Action, AnyAction, Dispatch } from 'redux'
1+
import type { Action, Dispatch, UnknownAction } from 'redux'
22
import type { Context } from 'react'
33

44
import type { ReactReduxContextValue } from '../components/Context'
@@ -13,7 +13,7 @@ import { useStore as useDefaultStore, createStoreHook } from './useStore'
1313
*/
1414
export function createDispatchHook<
1515
S = unknown,
16-
A extends Action = AnyAction
16+
A extends Action<string> = UnknownAction
1717
// @ts-ignore
1818
>(context?: Context<ReactReduxContextValue<S, A>> = ReactReduxContext) {
1919
const useStore =

src/hooks/useStore.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Context } from 'react'
2-
import type { Action as BasicAction, AnyAction, Store } from 'redux'
2+
import type { Action as BasicAction, UnknownAction, Store } from 'redux'
33
import type { ReactReduxContextValue } from '../components/Context'
44
import { ReactReduxContext } from '../components/Context'
55
import {
@@ -15,7 +15,7 @@ import {
1515
*/
1616
export function createStoreHook<
1717
S = unknown,
18-
A extends BasicAction = AnyAction
18+
A extends BasicAction = UnknownAction
1919
// @ts-ignore
2020
>(context?: Context<ReactReduxContextValue<S, A>> = ReactReduxContext) {
2121
const useReduxContext =
@@ -26,12 +26,12 @@ export function createStoreHook<
2626
createReduxContextHook(context)
2727
return function useStore<
2828
State = S,
29-
Action extends BasicAction = A
29+
Action2 extends BasicAction = A
3030
// @ts-ignore
3131
>() {
3232
const { store } = useReduxContext()!
3333
// @ts-ignore
34-
return store as Store<State, Action>
34+
return store as Store<State, Action2>
3535
}
3636
}
3737

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
FunctionComponent,
66
} from 'react'
77

8-
import type { Action, AnyAction, Dispatch } from 'redux'
8+
import type { Action, UnknownAction, Dispatch } from 'redux'
99

1010
import type { NonReactStatics } from 'hoist-non-react-statics'
1111

@@ -25,7 +25,7 @@ export type DistributiveOmit<T, K extends keyof T> = T extends unknown
2525
? Omit<T, K>
2626
: never
2727

28-
export interface DispatchProp<A extends Action = AnyAction> {
28+
export interface DispatchProp<A extends Action<string> = UnknownAction> {
2929
dispatch: Dispatch<A>
3030
}
3131

0 commit comments

Comments
 (0)