Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redux-thunk: Property 'type' missing when calling action through store.dispatch()

Tags:

I have found similar issues online but no solution for when calling a redux-thunk Action through store.dispatch().

I have the following action:

export class DBActions {   static startDatabase(): ThunkAction<Promise<void>, {}, IClientState, AnyAction> {     return async (dispatch: ThunkDispatch<{}, {}, AnyAction>, getState: () => IClientState): Promise<void> => {       return new Promise<void>((resolve) => {         dispatch(DBActions.connectDatabase())         setTimeout(() => {           let connection: (Connection | undefined) = getDBConnection(getState())           if (connection) {             dispatch(DBActions.getImports(connection))             resolve()           }         }, 2000)       })     }   } } 

This works without problems when added through mapDispatchToProps in a component, but not when directly called inside my store.ts after defining a store. store.dispatch(DBActions.startDatabase()) leads to:

TS2345: Argument of type 'ThunkAction<Promise<void>, {}, {}, AnyAction>' is not assignable to parameter of type 'AnyAction'.   Property 'type' is missing in type 'ThunkAction<Promise<void>, {}, {}, AnyAction>'. 

Any help and suggestion is appreciated!

like image 520
Shin Avatar asked Jan 25 '19 18:01

Shin


1 Answers

An easy workaround to avoid the error message - though it is not a solution is:

dispatch<any>(DBActions.getImports(connection)) 
like image 150
Rambatino Avatar answered Sep 28 '22 01:09

Rambatino