Skip to content
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bdec1e5
Updated tests to fix build Closed #95 (#133)
piotrwitek Feb 3, 2019
857d9fd
Adds info import module decleration (#134)
arshadkazmi42 Feb 4, 2019
23ffca5
Updated Recipes section Closed #137
piotrwitek Feb 12, 2019
8f51601
Updated TOC
piotrwitek Feb 12, 2019
af7d940
Updated deps (#139)
piotrwitek Feb 12, 2019
c06d37a
Added example for using context in class component (#141)
binoy14 Feb 14, 2019
33d96b6
Testing epics (#144)
piotrwitek Feb 22, 2019
8c796de
updated deps
piotrwitek Mar 7, 2019
1259b21
added redux-thunk types overload
piotrwitek Mar 7, 2019
d0a05b2
Updated legacy patterns
piotrwitek Mar 7, 2019
5d03b97
ThunkActionType prototype
piotrwitek Mar 7, 2019
342a6ad
fix spelling mistake (#152)
SCKelemen Apr 6, 2019
0ecf245
Updated docs and and example of integration with redux-thunk Resolved…
piotrwitek Apr 6, 2019
c8d35fe
Merge branch 'redux-thunk'
piotrwitek Apr 6, 2019
b5cefb4
Added hyperlinks for better UX
piotrwitek Apr 6, 2019
34fc808
Small updates
piotrwitek Apr 13, 2019
e732b43
Updated playground project and added integration with react-redux-typ…
piotrwitek Apr 13, 2019
3f978be
Added new solution to Connect with `react-redux` to solve validation …
piotrwitek Apr 13, 2019
acd9b20
Added ESLint config section (#158)
piotrwitek Apr 14, 2019
93fc2b8
Refactored playground to use create-react-app (#159)
piotrwitek Apr 14, 2019
cf8a03c
Capitalize file to fix import on POSIX systems (#160)
lordi Apr 15, 2019
05ddc8f
Added prettier to common npm scripts
piotrwitek Apr 18, 2019
0ff885d
Added doctoc
piotrwitek Apr 21, 2019
01bc1df
Updated readme
piotrwitek Apr 21, 2019
0c2afc9
Updated readme with new section about createReducer API
piotrwitek Apr 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ThunkActionType prototype
  • Loading branch information
piotrwitek committed Mar 7, 2019
commit 5d03b9741e36802e8b2741f940415ffad8ed266c
24 changes: 24 additions & 0 deletions playground/src/features/counters/thunk-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { action, ActionType } from 'typesafe-actions';

import { Dispatch, ActionCreatorsMapObject } from 'redux';
import * as actions from './actions';

// CLASSIC API
export const thunkIncrement = () => (dispatch: Dispatch) =>
dispatch(action('THUNK_INCREMENT'));
export const thunkAdd = (amount: number) => (dispatch: Dispatch) =>
dispatch(action('THUNK_ADD', amount));

type ThunkActionType<M extends ActionCreatorsMapObject<any>> = ActionType<
{
[N in keyof M]: ReturnType<M[N]> extends (
dispatch: Dispatch
) => { type: string }
? (...args: Parameters<M[N]>) => ReturnType<ReturnType<M[N]>>
: M[N]
}
>;

const thunkActions = { thunkIncrement, thunkAdd, ...actions };
export type Action = ThunkActionType<typeof thunkActions>;
// type Action = EmptyAction<"THUNK_INCREMENT"> | PayloadAction<"THUNK_ADD", number> | EmptyAction<"counters/INCREMENT"> | PayloadAction<"counters/ADD", number>