Last active
August 3, 2020 06:08
-
-
Save jakejrichards/ba871642c95bd0e5c757a9c97dfd082d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ThunkAction } from 'redux-thunk'; | |
import { ApplicationState, ApplicationAction } from './types'; | |
import { loadUsersRequest, loadUsersSuccess, loadUsersError } from './actions'; | |
import * as userService from '../services/userService'; | |
type Effect = ThunkAction<any, ApplicationState, any, ApplicationAction>; | |
export const loadUsers = (): Effect => (dispatch, getState) => { | |
dispatch(loadUsersRequest()); | |
// assume userService.loadUsers returns a Promise<User[]> | |
return userService.loadUsers() | |
.then(users => dispatch(loadUsersSuccess(users))) | |
.catch(() => dispatch(loadUsersError())); | |
}; |
what is the
type Effect
doing here? Why isloadUsers
not typed? How doesloadUsers
infer typing? Not following how this example demonstrates typing an async action creator with Redux.
I've updated the gist to correctly show how loadUsers
can infer the type. I accidentally left it out, thanks for pointing it out!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is the
type Effect
doing here? Why isloadUsers
not typed? How doesloadUsers
infer typing? Not following how this example demonstrates typing an async action creator with Redux.