Skip to content

Commit ed1126d

Browse files
committed
fix: make TS type defs conform to redux 4
1 parent d6eefa8 commit ed1126d

13 files changed

+155
-91
lines changed

.eslintrc.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ module.exports = {
44
env: {
55
es6: true,
66
},
7+
rules: {
8+
'@typescript-eslint/ban-types': 0,
9+
},
710
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"flow-bin": "^0.97.0",
4949
"mindfront-redux-utils": "^2.0.0",
5050
"mocha": "^10.2.0",
51-
"redux": "^3.6.0",
51+
"redux": "^4.2.1",
5252
"rimraf": "^2.6.0",
5353
"sinon": "^1.17.6",
5454
"typescript": "^5.2.2",

pnpm-lock.yaml

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions.d.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AnyAction } from 'redux'
12
import type { Feature, FeatureState, FeatureAction } from './index'
23
export declare const ACTION_TYPE_PREFIX = '@@redux-features/'
34
export declare const ADD_FEATURE: '@@redux-features/ADD_FEATURE'
@@ -6,19 +7,19 @@ export declare const LOAD_FEATURE: '@@redux-features/LOAD_FEATURE'
67
export declare const INSTALL_FEATURE: '@@redux-features/INSTALL_FEATURE'
78
export declare const SET_FEATURE_STATE: '@@redux-features/SET_FEATURE_STATE'
89
export declare const LOAD_INITIAL_FEATURES: '@@redux-features/LOAD_INITIAL_FEATURES'
9-
export declare function addFeature<S>(
10+
export declare function addFeature<S = any, A extends AnyAction = AnyAction>(
1011
id: string,
11-
feature: Feature<S>
12-
): FeatureAction
13-
export declare function replaceFeature<S>(
14-
id: string,
15-
feature: Feature<S>
12+
feature: Feature<S, A>
1613
): FeatureAction
14+
export declare function replaceFeature<
15+
S = any,
16+
A extends AnyAction = AnyAction
17+
>(id: string, feature: Feature<S, A>): FeatureAction
1718
export declare function loadFeature(id: string): FeatureAction
18-
export declare function installFeature<S>(
19-
id: string,
20-
feature: Feature<S>
21-
): FeatureAction
19+
export declare function installFeature<
20+
S = any,
21+
A extends AnyAction = AnyAction
22+
>(id: string, feature: Feature<S, A>): FeatureAction
2223
export declare function setFeatureState(
2324
id: string,
2425
payload: FeatureState

src/defaults.d.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
import type { Reducer, Middleware } from 'redux'
2-
export declare const defaultCreateReducer: (<S>(
3-
initialState: S,
4-
reducers: {
5-
[actionType: string]: Reducer<S>
6-
}
7-
) => Reducer<S>) &
8-
(<S>(reducers: { [actionType: string]: Reducer<S> }) => Reducer<S>)
9-
export declare function defaultComposeReducers<S>(
10-
...reducers: Array<Reducer<S>>
11-
): Reducer<S>
12-
export declare function defaultCreateMiddleware(middlewares: {
13-
[actionType: string]: Middleware
14-
}): Middleware
15-
export declare function defaultComposeMiddleware(
16-
...middlewares: Array<Middleware>
17-
): Middleware
1+
import type { Reducer, Middleware, AnyAction, Dispatch } from 'redux'
2+
export declare const defaultCreateReducer: {
3+
<S = any, A extends AnyAction = AnyAction>(
4+
initialState: S,
5+
reducers: Record<string, Reducer<S, A>>
6+
): Reducer<S, A>
7+
<S = any, A extends AnyAction = AnyAction>(
8+
reducers: Record<string, Reducer<S, A>>
9+
): Reducer<S, A>
10+
}
11+
export declare function defaultComposeReducers<
12+
S = any,
13+
A extends AnyAction = AnyAction
14+
>(...reducers: Array<Reducer<S, A>>): Reducer<S, A>
15+
export declare function defaultCreateMiddleware<
16+
DispatchExt = {},
17+
S = any,
18+
D extends Dispatch = Dispatch
19+
>(
20+
middlewares: Record<string, Middleware<DispatchExt, S, D>>
21+
): Middleware<DispatchExt, S, D>
22+
export declare function defaultComposeMiddleware<
23+
DispatchExt = {},
24+
S = any,
25+
D extends Dispatch = Dispatch
26+
>(
27+
...middlewares: Array<Middleware<DispatchExt, S, D>>
28+
): Middleware<DispatchExt, S, D>
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import type { Middleware } from 'redux'
1+
import type { Dispatch, Middleware } from 'redux'
22
import type { Features, ComposeMiddleware } from './index'
3-
export default function featureMiddlewaresMiddleware<S>(config?: {
4-
getFeatures?: (state: S) => Features<S> | null | undefined
5-
composeMiddleware?: ComposeMiddleware
6-
}): Middleware
3+
export default function featureMiddlewaresMiddleware<
4+
DispatchExt = {},
5+
S = any,
6+
D extends Dispatch = Dispatch
7+
>(config?: {
8+
getFeatures?: (state: S) => Features<S, Parameters<D>[0]> | null | undefined
9+
composeMiddleware?: ComposeMiddleware<DispatchExt, S, D>
10+
}): Middleware<DispatchExt, S, D>

src/featureReducersReducer.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import type { Reducer } from 'redux'
1+
import type { AnyAction, Reducer } from 'redux'
22
import type { Features, ComposeReducers } from './index'
3-
export default function featureReducersReducer<S>(config?: {
4-
getFeatures?: (state: S) => Features<S> | null | undefined
5-
composeReducers?: ComposeReducers<S>
6-
}): Reducer<S>
3+
export default function featureReducersReducer<
4+
S = any,
5+
A extends AnyAction = AnyAction
6+
>(config?: {
7+
getFeatures?: (state: S) => Features<S, A> | null | undefined
8+
composeReducers?: ComposeReducers<S, A>
9+
}): Reducer<S, A>

src/featureStatesReducer.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Reducer } from 'redux'
2-
import type { FeatureStates, CreateReducer } from './index'
3-
export default function featureStatesReducer(config?: {
4-
createReducer?: CreateReducer<FeatureStates>
5-
}): Reducer<FeatureStates>
2+
import type { FeatureStates, CreateReducer, FeatureAction } from './index'
3+
export default function featureStatesReducer<
4+
S extends FeatureStates = FeatureStates,
5+
A extends FeatureAction = FeatureAction
6+
>(config?: { createReducer?: CreateReducer<S, A> }): Reducer<S, A>

src/featuresReducer.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import type { Reducer } from 'redux'
1+
import type { AnyAction, Dispatch, Reducer } from 'redux'
22
import type { Features, CreateReducer } from './index'
3-
export default function featuresReducer<S>(config?: {
4-
createReducer?: CreateReducer<Features<S>>
5-
}): Reducer<Features<S>>
3+
export default function featuresReducer<
4+
S = any,
5+
A extends AnyAction = AnyAction,
6+
D extends Dispatch = Dispatch<A>
7+
>(config?: {
8+
createReducer?: CreateReducer<Features<S, A>>
9+
}): Reducer<Features<S, A, D>>

src/index.d.ts

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,47 @@ export {
4040
setFeatureState,
4141
loadInitialFeatures,
4242
}
43-
import type { MiddlewareAPI, Reducer, Middleware, ActionCreator } from 'redux'
44-
export type ActionCreators<K extends string | number | symbol, A> = Partial<
45-
Record<K, ActionCreator<A>>
46-
>
47-
export interface CreateReducer<S> {
48-
(
49-
initialState: S,
50-
reducers: {
51-
[actionType: string]: Reducer<S>
52-
}
53-
): Reducer<S>
54-
(reducers: { [actionType: string]: Reducer<S> }): Reducer<S>
43+
import type {
44+
MiddlewareAPI,
45+
Reducer,
46+
Middleware,
47+
AnyAction,
48+
Dispatch,
49+
} from 'redux'
50+
51+
export interface CreateReducer<S, A extends AnyAction = AnyAction> {
52+
(initialState: S, reducers: Record<A['type'], Reducer<S, A>>): Reducer<S>
53+
(reducers: Record<A['type'], Reducer<S, A>>): Reducer<S>
5554
}
56-
export type ComposeReducers<S> = (...reducers: Array<Reducer<S>>) => Reducer<S>
57-
export type ComposeMiddleware = (
58-
...middlewares: Array<Middleware>
59-
) => Middleware
55+
export type ComposeReducers<S, A extends AnyAction = AnyAction> = (
56+
...reducers: Array<Reducer<S, A>>
57+
) => Reducer<S, A>
58+
export type ComposeMiddleware<
59+
DispatchExt = {},
60+
S = any,
61+
D extends Dispatch = Dispatch
62+
> = (
63+
...middlewares: Array<Middleware<DispatchExt, S, D>>
64+
) => Middleware<DispatchExt, S, D>
6065
export type FeatureState = 'NOT_LOADED' | 'LOADING' | 'LOADED' | Error
61-
export type FeatureStates = {
62-
[featureId: string]: FeatureState
63-
}
64-
export type Feature<S> = {
65-
init?: (store: MiddlewareAPI<S>) => any
66-
load?: (store: MiddlewareAPI<S>) => Promise<Feature<S>>
66+
export type FeatureStates = Record<string, FeatureState>
67+
export type Feature<
68+
S = any,
69+
A extends AnyAction = AnyAction,
70+
D extends Dispatch = Dispatch<A>
71+
> = {
72+
init?: (store: MiddlewareAPI<D, S>) => any
73+
load?: (store: MiddlewareAPI<D, S>) => Promise<Feature<S, A>>
6774
dependencies?: Array<string>
68-
middleware?: Middleware
69-
reducer?: Reducer<S>
70-
}
71-
export type Features<S> = {
72-
[featureId: string]: Feature<S>
75+
middleware?: Middleware<any, S, D>
76+
reducer?: Reducer<S, A>
7377
}
78+
export type Features<
79+
S,
80+
A extends AnyAction = AnyAction,
81+
D extends Dispatch = Dispatch<A>
82+
> = Record<string, Feature<S, A, D>>
83+
7484
export type FeatureAction = {
7585
type: string
7686
payload?: any

0 commit comments

Comments
 (0)