Skip to content

ThunkApi.getState with Typescript #793

@atinyakov

Description

@atinyakov

Hi everyone!
How I can get rid of the following TS error?

export const getSibling = createAsyncThunk<
{response: Data},
{id: string},
{getState: () => RootState}
>(`Tree_data/fetch_sibling`, async({id}, thunkApi) => {
const {tree: {treeData}} = thunkApi.getState()

// omitted code
}

const RootState = ReturnType<typeof store.getState> exported from index.ts

In the snippet above TS shows an error : Type { omitted for brevity} has no properties in common with 'AsyncThunkConfig' for the {getState: () => RootState} line

Due to limitations of working machine the snippet was re-typed by hand, I hope that it will be enough. Thanks

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