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!
An easy workaround to avoid the error message - though it is not a solution is:
dispatch<any>(DBActions.getImports(connection))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With