diff --git a/src/actions/__tests__/index_spec.ts b/src/actions/__tests__/index_spec.ts index 6354ad9..e8d1061 100644 --- a/src/actions/__tests__/index_spec.ts +++ b/src/actions/__tests__/index_spec.ts @@ -69,7 +69,7 @@ describe('actions', () => { const { dispatch, reducer } = store() actions.saveCount({ value: 14 })(dispatch) return eventually(() => { - expect(reducer.mock.calls[1][1].error.message) + expect(reducer.mock.calls[1][1].error) .toEqual('something terrible happened') }) }) @@ -131,7 +131,7 @@ describe('actions', () => { const { dispatch, reducer } = store() actions.loadCount()(dispatch) return eventually(() => { - expect(reducer.mock.calls[1][1].error.message) + expect(reducer.mock.calls[1][1].error) .toEqual('something terrible happened') }) }) diff --git a/src/actions/action.ts b/src/actions/action.ts index ec6cc31..a3d28d3 100644 --- a/src/actions/action.ts +++ b/src/actions/action.ts @@ -1,29 +1,28 @@ type Q = { request: T } type S = { response: T } -type E = { error: Error } +type E = { error: string } -type QEmpty = Q<{}> -type QValue = Q<{ value: number }> +type Value = { value: number } -type LoadCount = - ({ type: 'LOAD_COUNT_REQUEST' } & QEmpty) - | ({ type: 'LOAD_COUNT_SUCCESS' } & QEmpty & S<{ value: number }>) - | ({ type: 'LOAD_COUNT_ERROR' } & QEmpty & E) +type LoadCountAction = + ({ type: 'LOAD_COUNT_REQUEST' } & Q<{}>) +| ({ type: 'LOAD_COUNT_SUCCESS' } & Q<{}> & S) +| ({ type: 'LOAD_COUNT_ERROR' } & Q<{}> & E) -type SaveCount = - ({ type: 'SAVE_COUNT_REQUEST' } & QValue) - | ({ type: 'SAVE_COUNT_SUCCESS' } & QValue & S<{}>) - | ({ type: 'SAVE_COUNT_ERROR' } & QValue & E) +type SaveCountAction = + ({ type: 'SAVE_COUNT_REQUEST' } & Q) +| ({ type: 'SAVE_COUNT_SUCCESS' } & Q & S<{}>) +| ({ type: 'SAVE_COUNT_ERROR' } & Q & E) export type Action = - LoadCount -| SaveCount + LoadCountAction +| SaveCountAction | { type: 'INCREMENT_COUNTER', delta: number } | { type: 'RESET_COUNTER' } type _T = Action['type'] -type APIActionGroup = +type ThunkActionGroup = ({ type: TQ } & Q<_Q>) | ({ type: TS } & Q<_Q> & S<_S>) | ({ type: TE } & Q<_Q> & E) @@ -34,9 +33,9 @@ type Thunk = (request: Q) => Promise export const createThunkAction = (fn: Thunk, tq: TQ, ts: TS, te: TE) => (request: Q) => - (dispatch: Dispatch>) => { + (dispatch: Dispatch>) => { dispatch({ type: tq, request }) fn(request) .then(response => dispatch({ type: ts, request, response })) - .catch(error => dispatch({ type: te, request, error })) + .catch(err => dispatch({ type: te, request, error: err.message })) } diff --git a/src/reducers/index.ts b/src/reducers/index.ts index ce99663..bbb30b3 100644 --- a/src/reducers/index.ts +++ b/src/reducers/index.ts @@ -42,7 +42,7 @@ function error (state: string = '', action: Action): string { return '' case 'LOAD_COUNT_ERROR': case 'SAVE_COUNT_ERROR': - return action.error.toString() + return action.error default: return state }