TypeScript createAsyncThunk optional or no args
See original GitHub issueI am trying to make an api call with an optional parameter however typescript complains
export const usersLoad = createAsyncThunk(
'users/load',
(filters: UserFilters = {}) => Api.get<User[]>('/api/users/search', filters)
);
...
dispatch(usersLoad());
Expected 1 arguments, but got 0
I have a similar issue with this action
export const usersLoadMore = createAsyncThunk(
'users/loadMore',
(_: SyntheticEvent | void, thunkApi) => {
const state = thunkApi.getState() as RootState;
const { filters, data } = state.users;
return Api.get<User[]>('/api/users/search', {
...filters,
offset: data.length,
});
}
);
here I don’t use the arg but I had to give it the SyntheticEvent or it complained when passing it to onClick, and I had to give it void to make it work when I call it directly. I would think that I would not have to set it to anything since I am not using it.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:27 (7 by maintainers)
Top Results From Across the Web
How to use createAsyncThunk from Redux Toolkit with ...
Expected 1 arguments, but got 0. createAsyncThunk.d.ts(107, 118): An argument for 'arg' was not provided. I have similar code in the project ...
Read more >createAsyncThunk() function do I need to pass a parameter in ...
Hello! While using reduxjs/toolkit - createAsyncThunk() function do I need to pass a parameter in the async() function?
Read more >createAsyncThunk - Redux Toolkit
An object with the following optional fields: condition(arg, { getState, extra } ): boolean | Promise<boolean> : a callback that can be used...
Read more >Using Redux Toolkit's createAsyncThunk - LogRocket Blog
While a Redux store possesses great state management features, it has no clue how to deal with asynchronous logic.
Read more >How to Use Thunks with Redux Toolkit and TypeScript
import { createAsyncThunk } from "@reduxjs/toolkit"; export const fetchTodos = createAsyncThunk( // The first argument is the action name: "todos/fetch",
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes. As I said:
We simply didn’t anticipate this use case and none of our beta testers had it either, so we’ll have to add it.
For anyone who comes across this in the future, I solved the no argument requirement in my TypeScript application by using the
_
discard operator as the first parameter to thepayloadCreator
function - whether this is correct or not is another matter.An example is below: