-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Prevent inference of any in create.asyncThunk #4389
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 10fae1a:
|
size-limit report 📦
|
This seems to fail a lot of tests 🤔 But weird as it is, if you get it working, I'm not opposed to a change like this - seems to fix a real bug. |
heh, those tests are relying on broken behaviour - will fix when i can |
@@ -678,7 +678,7 @@ describe('createSlice', () => { | |||
initialState: [] as any[], | |||
reducers: (create) => ({ | |||
thunkReducers: create.asyncThunk( | |||
function payloadCreator(arg, api) { | |||
function payloadCreator(arg: string, api) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... This brings up the question: will this still be okay in an untyped .js
file for non-TS-users or will it make it unusable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's the same behaviour as createAsyncThunk
. if they're not using type checking on their JS there will be nothing to complain, and if they are then they'll need to annotate:
const getPost = createAsyncThunk(
'posts/getPost',
/**
*
* @param {number} id
* @returns {Promise<Post>}
*/
async (id) => {
const response = await fetch(
`https://jsonplaceholder.typicode.com/posts/${id}`,
)
const data = await response.json()
return data
},
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can even set the ApiConfig:
const getPost = createAsyncThunk(
'posts/getPost',
/** @type {import("@reduxjs/toolkit").AsyncThunkPayloadCreator<Post, number, { state: RootState }>}*/
async (id, api) => {
const response = await fetch(
`https://jsonplaceholder.typicode.com/posts/${id}`,
)
const data = await response.json()
return data
},
)
fixes #4060 (comment)
we're also making this change over in #3894 (https://github.com/reduxjs/redux-toolkit/pull/3894/files#diff-ee57feab8b392faa360ea66691a847a2dbed2f82486f5726c3723d6a194f22f0R507) so it's mostly unavoidable once we have creators