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

Types for dispatch with thunk are incorrect #148

Open
ChuckJonas opened this issue May 10, 2018 · 8 comments
Open

Types for dispatch with thunk are incorrect #148

ChuckJonas opened this issue May 10, 2018 · 8 comments

Comments

@ChuckJonas
Copy link

If I load you async example into a project, i get the following error on return store.dispatch(fetchData())

Argument of type '(dispatch: any) => Promise<any>' is not assignable to parameter of type 'Action'.
  Property 'type' is missing in type '(dispatch: any) => Promise<any>'.

Using Redux 4.0

@flq
Copy link

flq commented Jun 1, 2018

Can confirm, with redux 4 types ain’t working.

@martpie
Copy link

martpie commented Jun 7, 2018

I can confirm it too.

@flq
Copy link

flq commented Jun 7, 2018

Since it doesn’t look lile this package is maintained we switched to some custom code - at the end we didn’t need full store semantics in our action tests, but just a working dispatcher and a way to collect dispatched actions

@chungnho
Copy link

This is probably a problem with the @types/redux-mock-store package rather than this one. https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/redux-mock-store

That package lists redux@3.6.0 as a dependency and since there were significant type changes between redux@3 and redux@4 new types will need to be submitted to DefinitelyTyped that are compatible with redux@4

@chungnho
Copy link

Just submitted this update which should allow you to add the ThunkDispatch signature when creating the store: DefinitelyTyped/DefinitelyTyped#26732

When that is merged and released you can do something like:

const middlewares: Array<Middleware> = [thunk]
type DispatchExts = ThunkDispatch<RootState, undefined, AnyAction>
const mockStoreCreator: MockStoreCreator<RootState, DispatchExts> = 
    createMockStore<RootState, DispatchExts>(middlewares)
const store: MockStoreEnhanced<RootState, DispatchExts> = mockStoreCreator({})

@mpcen
Copy link

mpcen commented Jul 7, 2018

@chungnho Thank you sir. Took me 5 hours to find this.

@kgajowy
Copy link

kgajowy commented Sep 21, 2018

👍 to put this in the docs

@jednano
Copy link

jednano commented Jul 12, 2019

I made a TypeScript fork of this library and resolved some open issues at @jedmao/redux-mock-store.

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

7 participants