endreymarcell / effin-redux

Extend redux-toolkit with effects and more.
https://endreymarcell.github.io/effin-redux/
MIT License
0 stars 0 forks source link

Using the thunkAPI argument of effects creates circular type definition #1

Open endreymarcell opened 1 year ago

endreymarcell commented 1 year ago

When reading the state or dispatching an action from within an effect via the thunkAPI argument, both the effect inputs and the slice become any because their types depend on each other. Functionality is unaffected.

endreymarcell commented 1 year ago

Workaround: first save the action into a variable that is explicitly types as any:

Type error

startCountingInterval: async (_unused, thunkAPI) => {
  setInterval(() => thunkAPI.dispatch(counterSlice.actions.countIntervalTicked()), 1000);
},

Workaround

startCountingInterval: async (_unused, thunkAPI) => {
  const actionToDispatch: any = counterSlice.actions.countIntervalTicked();
  setInterval(() => thunkAPI.dispatch(actionToDispatch), 1000);
},