The createAsyncThunk
can have the types defined on the generics:
export const unsubscribeMeta = createAsyncThunk<apiUnsubscribeResponse, void, {state: RootState }>(
'meta/unsubscribe',
async (_, { getState }) => {
const { meta } = getState();
const res = await client.post<apiUnsubscribeResponse>(
`/meta/unsubscribe/${meta.subscriptionId}`
);
return res.data.data;
}
);
Defining the state
will automatically make the getState be aware of the application state.