I'm struggling to find the right type for my return type of a AsyncThunkAction to use it with the unwrapResult method of Redux Toolkit (see: Redux Tookit: Unwrapping Result Actions):
Declaration of Async thunk in Slice:
export
const createChannel = createAsyncThunk<
{ id: string },
ChannelReqDto,
InjectedAxiosClientType
>("channel/createChannel", async (req, thunkApi) => {
const result = await thunkApi.extra.client.post(
`/store/${req.storeId}/channels`,
{
category: req.category,
group: req.group,
name: req.name,
rules: [],
}
);
return result.data;
});
Usage in React Component:
const newChannel = await dispatch(
createChannel({
name: name,
group: group,
category: category,
storeId: storeIdParam,
rules: [],
})
);
const result = unwrapResult(newChannel);
TypeScript Error:
TS2345: Argument of type 'AsyncThunkAction<{ id: string; }, ChannelReqDto, InjectedAxiosClientType>' is not assignable to parameter of type 'UnwrappableAction'. Property 'payload' is missing in type 'AsyncThunkAction<{ id: string; }, ChannelReqDto, InjectedAxiosClientType>' but required in type 'UnwrappableAction'.
The result type needs to extend the interface UnwrappableAction but somehow I can't get it to work without ts-ignore:
export declare function unwrapResult<R extends UnwrappableAction>(action: R): UnwrappedActionPayload<R>;