Skip to content
This repository was archived by the owner on Jun 8, 2022. It is now read-only.

Commit 2a66f6d

Browse files
committed
Move Reducer type to types file
1 parent 7975e13 commit 2a66f6d

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/ducks/test/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import * as i from 'types';
55
import { HYDRATE } from 'next-redux-wrapper';
66
import { action } from 'typesafe-actions';
77

8-
// Duck name, State struct type, typeof actions object
9-
type Reducer = i.Reducer<'test', i.TestState, typeof testActions>;
8+
import { TestReducer } from './types';
109

1110
export const testActions = {
1211
load: () => action('test/GET'),
@@ -20,7 +19,7 @@ const initialState: i.TestState = {
2019
loading: false,
2120
};
2221

23-
const reducer: Reducer = (state = initialState, action) => {
22+
const reducer: TestReducer = (state = initialState, action) => {
2423
switch (action.type) {
2524
// HYDRATE is explained here:
2625
// https://github.com/kirill-konshin/next-redux-wrapper#state-reconciliation-during-hydration

src/ducks/test/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import * as i from 'types';
22

3+
import { testActions } from '.';
4+
35
export type TestState = {
46
data: boolean | null;
57
error: boolean;
68
loading: boolean;
79
};
810

11+
// Duck name, State struct type, typeof actions object
12+
export type TestReducer = i.Reducer<'test', i.TestState, typeof testActions>;
13+
914
export type GetData = i.BaseThunkAction<() => Promise<void>>;

src/types/redux.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ type HydrateAction<N extends string, S> = {
3636
};
3737

3838
export type Reducer<
39-
N extends string,
40-
S extends i.AnyObject,
41-
A extends Record<string, (...args: any) => EmptyAction<any> | PayloadAction<any, any> | PayloadMetaAction<any, any, any>>
42-
> =
43-
(
44-
state: S,
45-
action: HydrateAction<N, S> | ActionType<A>,
46-
) => S;
39+
Name extends string,
40+
State extends i.AnyObject,
41+
Actions extends Record<string, (...args: any) => EmptyAction<any> | PayloadAction<any, any> | PayloadMetaAction<any, any, any>>
42+
> = (
43+
state: State,
44+
action: HydrateAction<Name, State> | ActionType<Actions>,
45+
) => State;
4746

4847
/** Thunk action type with pre-filled generics. */
4948
type ExtraArgument = i.AnyObject;

0 commit comments

Comments
 (0)