Skip to content
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

Merged
merged 2 commits into from
May 9, 2024

Conversation

EskiMojo14
Copy link
Collaborator

@EskiMojo14 EskiMojo14 commented May 3, 2024

Copy link

codesandbox bot commented May 3, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

netlify bot commented May 3, 2024

Deploy Preview for redux-starter-kit-docs ready!

Name Link
🔨 Latest commit 10fae1a
🔍 Latest deploy log https://app.netlify.com/sites/redux-starter-kit-docs/deploys/6636230a4c73770008104a14
😎 Deploy Preview https://deploy-preview-4389--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codesandbox-ci bot commented May 3, 2024

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:

Sandbox Source
rsk-github-issues-example Configuration
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration
rtk-esm-cra Configuration

Copy link

github-actions bot commented May 3, 2024

size-limit report 📦

Path Size

@phryneas
Copy link
Member

phryneas commented May 3, 2024

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.

@EskiMojo14
Copy link
Collaborator Author

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) {
Copy link
Member

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?

Copy link
Collaborator Author

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
  },
)

Copy link
Collaborator Author

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
  },
)

@markerikson markerikson merged commit f17e122 into master May 9, 2024
48 checks passed
@markerikson markerikson deleted the infer-void-async-thunk branch May 9, 2024 01:24
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

Successfully merging this pull request may close these issues.

Wrong AsyncThunkAction args type when creating a thunk without args using create.asyncThunk
3 participants