async / await and AppThunkAction - TypeScript/React/Redux - Question #278

Closed
opened 2025-08-09 17:15:40 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @jonorogers on 12/10/2017

What's the best way to mix the new async/await operators with redux thunk actions when using TypeScript/React/Redux?

I've tried marking the action creator as async:

requestWeatherForecasts: async (startDateIndex: number): AppThunkAction<KnownAction> => (dispatch, getState) => {

But it brings up the following error:

(TS) Type 'AppThunkAction' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.

I've also tried returning async dispatch from the action:

requestWeatherForecasts: (startDateIndex: number): AppThunkAction<KnownAction> => (dispatch, getState) => {

        return async dispatch => {

        }

But that says dispatch is implicitly any:

(TS) Parameter 'dispatch' implicitly has an 'any' type.

I've tried various ways of adding the correct type definition to dispatch inline, but can't seem to get anything working.

*Originally created by @jonorogers on 12/10/2017* What's the best way to mix the new async/await operators with redux thunk actions when using TypeScript/React/Redux? I've tried marking the action creator as async: `requestWeatherForecasts: async (startDateIndex: number): AppThunkAction<KnownAction> => (dispatch, getState) => {` But it brings up the following error: > (TS) Type 'AppThunkAction' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. I've also tried returning async dispatch from the action: ``` requestWeatherForecasts: (startDateIndex: number): AppThunkAction<KnownAction> => (dispatch, getState) => { return async dispatch => { } ``` But that says dispatch is implicitly any: > (TS) Parameter 'dispatch' implicitly has an 'any' type. I've tried various ways of adding the correct type definition to dispatch inline, but can't seem to get anything working.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#278
No description provided.