Skip to content

Typescript: createAsyncThunk, Expected 0 arguments, but got 1 #968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ViaxCo opened this issue Mar 31, 2021 · 2 comments
Closed

Typescript: createAsyncThunk, Expected 0 arguments, but got 1 #968

ViaxCo opened this issue Mar 31, 2021 · 2 comments

Comments

@ViaxCo
Copy link

ViaxCo commented Mar 31, 2021

Working on a regular JS project in VSCode which uses Typescript to check the files, using createAsyncThunk with an argument causes type errors:

export const addPost = createAsyncThunk("posts/addPost", async post => {});
// somewhere else...
dispatch(addPost(post))

Type error: Expected 0 arguments, but got 1

I understand that the argument in the payloadCreator is typed as void by default and if this was a regular TS project, I could've easily added a type for the post or even typed it as any, but seeing as that is not possible, I would be grateful for a JS solution. I don't seem to be able to extend types either.

@phryneas
Copy link
Member

phryneas commented Apr 1, 2021

You can work around that by adding a docblock with a parameter type, like described here: #814 (comment)

@ViaxCo
Copy link
Author

ViaxCo commented Apr 1, 2021

Thanks! That's just what I needed.

@ViaxCo ViaxCo closed this as completed Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants