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

bindThunkAction uses incorrect typings for dispatch #12

Closed
jussikinnula opened this issue May 15, 2018 · 3 comments
Closed

bindThunkAction uses incorrect typings for dispatch #12

jussikinnula opened this issue May 15, 2018 · 3 comments

Comments

@jussikinnula
Copy link

This is for the old typescript-fsa-redux-thunk v1.0.1 (I did try already 2.0.0 beta.8, but the examples didn't work, and it might actually not be production ready yet).

Example code:

import actionCreatorFactory from 'typescript-fsa';
import { bindThunkAction } from 'typescript-fsa-redux-thunk';
const actionCreator = actionCreatorFactory();

export const fooAsync = actionCreator.async<string, number>('FOO');
export const foo = bindThunkAction(fooAsync, (param) => {
  return Promise.resolve(param.length);
});

export const barAsync = actionCreator.async<string, number>('BAR');
export const bar = bindThunkAction(barAsync, async (param, dispatch) => {
  const result = await dispatch(foo(param));
  // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  return Promise.resolve(param.length);
});

Using dispatch(foo(param))) gives an error: Type '{ async: AsyncActionCreators<any, any, Error>; action: ThunkActionCreator<any, Promise<any>, stri...' is not assignable to type 'ActionCreator<any>'.

The workaround we're using at the moment is to define type for dispatch as plain Function.

I know that typescript-fsa-redux-thunk v2 should fix also the issue, but it would be nice to try to fix v1 also before getting v2 production ready.

@xdave
Copy link
Owner

xdave commented May 17, 2018

Hmm can you explain what was wrong with the examples for v2?

@xdave
Copy link
Owner

xdave commented May 17, 2018

Also, for the v1 error, can you try specifying types for the state and the error?, ie:

const fooAsync = actionCreator.async<State, string, number, Error>('FOO');

redux-thunk contains an overload for dispatch which should accept the result of a thunk. I wonder if that'll make it work.

@xdave
Copy link
Owner

xdave commented May 30, 2018

@jussikinnula I'm probably not going to backport a fix for 1.x at this point. I've updated the v2 branch (beta version) to support redux@4.x and redux-thunk@2.3.x. Please see here for more details: #11 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants