I was following along with the Redux Essentials Tutorials on how to employ createAsyncThunk
for generating Thunks. In their example here they create a thunk like so:
export const addNewPost = createAsyncThunk(
'posts/addNewPost',
async (initialPost) => { // Note: initialPost is an object with 3 props: title, content, user
const response = await client.post('/fakeApi/posts', initialPost)
return response.data
}
)
and they call it in another file like this:
await dispatch(addNewPost({ title, content, user: userId }))
In my project I've installed typescript and react types (@types/react
). Even though the code is JavaScript, this gives me intellisense from VSCode IDE on proper typings. However when I do above I see:
The typings expects 0 arguments but gets one, my object. Hovering over the method addNewPost
I see that it takes no args and returns the async action.
How can I have my IDE and typescript typings support recognize the the proper params required?
What I tried
Tried to add some JSDOC string to the created addNewPost
function like so:
/**
* addNewPost
* @returns {(initialPost:{title:string, content:string, user: string}) => void} the returned action create takes an object as arg
*/
export const addNewPost = createAsyncThunk(
'posts/addNewPost',
async (initialPost) => {
const response = await client.post('/fakeApi/posts', initialPost)
...
Following another Stack Overflow suggestion on how to use JSDocs to describe a returned function. but that doesn't seem to work.
Anyone have any suggestions?