How can I configure Typescript to work with react-redux and redux-thunk so that dispatch returns the return type of the ThunkAction getting dispatched instead of a ThunkAction<a,b,c,d,e>?
export function addPerson(
person: Person
): PersonActionTypes {
return {
type: ADD_PERSON,
person,
}
}
export const savePerson = (
person: Person
): ThunkAction<
Promise<Person>,
RootState,
unknown,
Action<string>
> => async (dispatch): Promise<Person> => {
const savedPerson = await PersonApi.save(person)
dispatch(addPerson(savedPerson))
return savedPerson
}
When I dispatch this action, I would like for it return a Promise<Person> but dispatch returns ThunkAction<Promise<void>, RootState, unknown, Action<string>>
const savedPerson = await dispatch(savePerson(person))
// savedPerson is a ThunkAction as far as TypeScript is concerned but I would like it to be a Person.