logux / redux

Redux compatible API for Logux
https://logux.org/
MIT License
127 stars 16 forks source link

Troubles with dispatch types in connect #25

Closed dotterian closed 4 years ago

dotterian commented 4 years ago

Redux's connect implores that dispatch is of type Redux.Dispatch, hence we can't use LoguxDispatch and code like this will produce errors:

connect(null, dispatch => ({
  doSomething: () => dispatch.sync({ type: 'SOME_ACTION' }) // Property 'sync' does not exist on type 'Dispatch<Action<any>>'
}))(SomeComponent)

Extracting MapDispatchToProps into separate variable with parameter type of LoguxDispatch also breaks things:

const mapDispatchToProps = (dispatch: LoguxDispatch<Action>) => ({
  doSomething: () => dispatch.sync({ type: 'SOME_ACTION' })
})

connect(null, mapDispatchToProps)(SomeComponent) // No overload matches this call

At the time I have no ideas how to solve this problem except // @ts-ignore, which is obviously bad.

One possible (but not so good) solution that comes to my mind is to export connect from @logux/redux with modified typescript signatures.

ai commented 4 years ago

Am I right that it is TS only problem and you will see sync property in the browser?

dotterian commented 4 years ago

Yes, it's types related and if I ignore typechecking for this line it works perfectly.

ai commented 4 years ago

connect is Redux method, do you have any idea how to fix types there?

ai commented 4 years ago

Sorry, have no idea how to fix it for now