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

typeActionCreator is undefined for createAsyncThunk.withTypes #2884

Closed
gitChaoslord opened this issue Nov 8, 2022 · 4 comments · Fixed by #2885
Closed

typeActionCreator is undefined for createAsyncThunk.withTypes #2884

gitChaoslord opened this issue Nov 8, 2022 · 4 comments · Fixed by #2885
Milestone

Comments

@gitChaoslord
Copy link

Description:

I followed the instructions of defining a pre typed async thunk to use the new createAsynkThunk.withTypes<AsyncThunkConfig>() in order to have types available in my slices.

Expected behaviour:

I expected to be able to access the ThunkApi properties defined in the AsynkThunkConfig in my created async thunks.

Current behaviour:

The types are correctly inferred but the action creators are not being created and I receive the following error when I use the newly created createAppAsyncThunk function.

Error Message:

Firefox
Message: can't access property "type", typeOrActionCreator is undefined
Error in @reduxjs/toolkit@1.9.0/dist/redux-toolkit.cjs.development.js (607:24)

Chrome 
Message: Cannot read properties of undefined (reading 'type')
Error in @reduxjs/toolkit@1.9.0/dist/redux-toolkit.cjs.development.js (607:108)

Here is a Stackblitz with my issue: https://stackblitz.com/edit/react-ts-jdymnd?file=store%2Ffeatures%2Fslice.ts

Other Information:

RTK version 1.9.0
Typescript: 4.8.4
React 18.2.0
React-redux 8.0.5
Redux 4.20

@gitChaoslord gitChaoslord changed the title Possible bug: typeActionCreator is undefined for createAsyncThunk.withTypes typeActionCreator is undefined for createAsyncThunk.withTypes Nov 8, 2022
@markerikson markerikson added this to the 1.9.x milestone Nov 8, 2022
@markerikson
Copy link
Collaborator

Yes, it appears that we lied to TypeScript and are returning a thunk function, not createAsyncThunk itself with more types attached.

This is a bug and we ought to fix it ASAP.

@phryneas
Copy link
Member

phryneas commented Nov 8, 2022

Could you please try the build of #2885?
You can find install instructions on https://ci.codesandbox.io/status/reduxjs/redux-toolkit/pr/2885/

@markerikson
Copy link
Collaborator

Also found out that fulfillWithValue has bad types, per #2886 .

@markerikson
Copy link
Collaborator

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 a pull request may close this issue.

3 participants