Skip to content

Have to pass types explicitly in createAsyncThunk #2150

@original001

Description

@original001

Hi! I want to use createAsyncThunk in my project, but there is some problems:

  1. Every time I want to use createAsyncThunk, I must pass types explicitly. Otherwise, I don't get types of state, extra, etc.
  2. 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 when
export interface DefaultRootState {}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions