-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
Store type mismatch when using redux-thunk #207
Comments
Can you make a repo to reproduce this? |
Of course, I made it here (I rewrote it from the above code to match v6.0.0) |
Thank you, I will look into it. |
@suzu2469 Did you find solution? I have the same problem... |
I haven't had time to look into this particular issue, sorry. It's in the backlog, I will fix it as soon as I can. In the mean time you guys are most welcome to investigate it too. |
I seem to be having this issue (without redux-toolkit) as well but for the time being whenever I use the dispatch, I make sure to cast it to a
|
This part looks relevant:
From my understanding, the problem is that export function configureStore<
S = any,
A extends Action = AnyAction,
M extends Middlewares<S> = [ThunkMiddlewareFor<S>]
>(options: ConfigureStoreOptions<S, A, M>): EnhancedStore<S, A, M> export interface EnhancedStore<
S = any,
A extends Action = AnyAction,
M extends Middlewares<S> = Middlewares<S>
> extends Store<S, A> (source) I tried to play with the TypeScript declarations but wasn't able to get it to work. @kirill-konshin What do you think? |
@eyalch makes sense to me. Feel free to send me a PR. |
support stores that `extends Store` and thus providing typing for something like Redux Toolkit's `EnhancedStore` BREAKING CHANGE: change some of the types' signatures Fixes kirill-konshin#207
@kirill-konshin could you please approve the PR so that this issue is closed. This behavior is unwanted in case of |
@nikhilraj1997 there are open questions in the PR, if you can help to resolve them — you're most welcome. |
@kirill-konshin I really appreciate your work on |
@nikhilraj1997 well go ahead and give it a shot ))). That’s what open source is all about ) I simply don’t have enough time at the moment and the proposed change tends to be a major release, which should not happen for a change like what’s proposed. So if anyone can step up and make it work within a minor release - I’d gladly accept the contribution. As of for now, either I’ll make a major release or find time to investigate... |
Any news? |
I am still not having enough time to fix this at the moment. If anyone can attempt to fix it w/o publishing a major release — you are most welcome... |
While the issue isn't fixed you can use the following workaround:
|
@adonig you're right, that's the correct way, according to docs: https://redux-toolkit.js.org/usage/usage-with-typescript#getting-the-dispatch-type import { configureStore } from '@reduxjs/toolkit'
import { useDispatch } from 'react-redux'
import rootReducer from './rootReducer'
const store = configureStore({
reducer: rootReducer
})
export type AppDispatch = typeof store.dispatch
export const useAppDispatch = () => useDispatch<AppDispatch>() // Export a hook that can be reused to resolve types Looks like even Redux Thunk itself does not have a cleaner way to tell store that it has modified the Closing. |
P.S. Will be fixed in |
Use #295 to track progress. |
It's an awesome update but I still have some questions. I've already updated to |
@Kupstas weird. Take a look at this demo here: https://github.com/kirill-konshin/next-redux-wrapper/tree/types-enchancements/packages/demo-dynamic — |
@kirill-konshin I removed type of makeStore method and it worked. Really thanks, you did a great job! |
* Fix #280 * Fix #207 * Minor fixes * Updated API * Updated versions * Update README.md * Fixed demos & tests * Github Action * Make demo-dynamic private * Fix #326 * Fix hot reloading issues by removing the store from window (#324) Co-authored-by: Melanie Seltzer <melleh11@gmail.com> Co-authored-by: Daniel Ferenc Balogh <danielferencortel@gmail.com>
I use redux-thunk not redux-toolkit or typescript, and I have the same problem. |
I want to use thunk's AsyncAction from getInitialProps, but the type doesn't match.
So this is how I wanted to solve it, but I couldn't.
I'm using redux-toolkit, but I think maybe even if someone is using pure thunk they'll have the same problem.
Please let me know if you have any other solutions.
The text was updated successfully, but these errors were encountered: