I can try to implement the weather app using redux with typescript but i can get error called Argument of type 'ThunkAction<void, CombinedState<{ weather: WeatherState; alert: AlertState; }>, null, WeatherAction>' is not assignable to parameter of type 'AnyAction'.
I can expect the answer from you.
CodePudding user response:
Please follow the TypeScript QuickStart for Redux and create correctly typed useAppDispatch
hooks for your application. The useDispatch
hook itself does not know if you have the thunk
middleware active and does not take it into account.
CodePudding user response:
These are two distinct problems. Typing in any way will never influence runtime behavior.
Firstly: So your thunk not firing any other action can only have one meaning: The other calls to dispatch
are most likely never reached. Are you sure your call to fetch
ever terminates? It might just wait forever for an answer or something like that.
Second, your typing issue: the standard Dispatch
type does not support thunks by default. Your solution with Dispatch<any>
is okay. Otherwise, you could cast your dispatch
function to ThunkDispatch
from the redux-thunk
package.
I advice you to follow this documentation