You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I want to use createAsyncThunk in my project, but there is some problems:
Every time I want to use createAsyncThunk, I must pass types explicitly. Otherwise, I don't get types of state, extra, etc.
If I pass my types, I lose type inferring of payloadCreator result. I need pass it explicitly too. Also, type of thunk argument moved to generic.
There are some redux libraries there is possible to redefine global interfaces. For example, react-redux do like that:
// This interface can be augmented by users to add default types for the root state whenexportinterfaceDefaultRootState{}
This way is more convinient and can resolve these problems. I don't see any problems with that solution. In redux project is only one state.
In redux-toolkit I didn't find the same approach. ThunkApi depends on declare type AsyncThunkConfig, which I cannot redefine.
The text was updated successfully, but these errors were encountered:
original001
changed the title
createAsyncThunk demands on my types, that I must pass explicitly
Have to pass types explicitly in createAsyncThunk
Mar 21, 2022
Frankly, a simpler option here is to just do const state = getState() as MyAppRootState. You're really not going to lose any meaningful type safety there.
Hi! I want to use createAsyncThunk in my project, but there is some problems:
There are some redux libraries there is possible to redefine global interfaces. For example, react-redux do like that:
This way is more convinient and can resolve these problems. I don't see any problems with that solution. In redux project is only one state.
In redux-toolkit I didn't find the same approach.
ThunkApi
depends ondeclare type AsyncThunkConfig
, which I cannot redefine.The text was updated successfully, but these errors were encountered: