-
Notifications
You must be signed in to change notification settings - Fork 28
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
Some breakage with new 3.0 beta #56
Comments
Alright, here's a smaller test case: import actionCreatorFactory, { AsyncActionCreators } from 'typescript-fsa';
const create = actionCreatorFactory();
const asyncActions = create.async<string, boolean>('SOME_ACTION');
const something = <P, S>(
actions: AsyncActionCreators<P, S, any>,
params: P,
result: S
) => {
actions.started(params);
actions.failed({ params, error: 'some error' });
actions.done({ params, result });
};
something(asyncActions, 'test', true);
|
OK if I change interface ActionCreator<P> {
type: string;
match: (action: AnyAction) => action is Action<P>;
(payload: P, meta?: Meta): Action<P>;
(payload?: P, meta?: Meta): Action<P>;
} Calling For example: const something = <P, S>(actions: AsyncActionCreators<P, S, any>, params?: P, result?: S) => {
actions.started(params);
actions.failed({ params } as Failure<P, any>);
actions.done({ params, result } as Success<P, S>);
}; After this, the types of the values in the reducer are correct, too. |
Just adding my notes here, that I have a package that is incorporated into another, and when using 3.0.0-beta.1, TS reported that the typings file for typescript-fsa had formatting issues. Which didn't make a lot of sense (it looked fine), but may be part of this problem. |
@suutari-ai Thanks... I haven't had the chance to check it yet, but I will see this weekend. |
@rplotkin need to make sure your editor/project is using TypeScript 2.8 to parse/check. new typescript-fsa uses conditional types, which were not supported in earlier versions of Typescript. |
Thanks for your report @xdave! |
@xdave Please try out |
@aikoven Hmm, so this makes my test case above pass, but beta version of my package is still failing around the optional params, etc. I'll have to see if I can massage my code to handle optional in the same way as yours with Until then, I'm passing |
@xdave Could you please post these other problems you get? |
@aikoven For example: export const bindThunkAction = <Params, Succ, Err, State, Extra = any>(
actionCreators: AsyncActionCreators<Params, Succ, Err>,
asyncWorker: AsyncWorker<Params, Succ, State, Extra>
): ThunkActionCreator<Params, Promise<Succ>, State, Extra> => params => async (
dispatch,
getState,
extra
) => {
try {
dispatch(actionCreators.started(params));
const result = await asyncWorker(params, dispatch, getState, extra);
dispatch(actionCreators.done({ params, result }));
return result;
} catch (error) {
dispatch(actionCreators.failed({ params, error }));
throw error;
}
}; Yields:
Because export type ThunkActionCreator<Params, Result, State, Extra> =
(params?: Params) => ThunkAction<Result, State, Extra, AnyAction>; So, the type of |
@aikoven I realize that even though having nice optional params in my library is convenient, it's not type-safe because you can still call a thunk that does take params without them. I need to adjust the way I optionalize it in my code. |
My package,
typescript-fsa-redux-thunk
and my attempts to refactor it have failed, and this also affectstypescript-fsa-reducers
. The best way to explain the errors I'm getting is to post a test case and explain where the errors are:There are only three errors, and interestingly, all occurring inside of my
bindThunkAction
function where the async actions are called:I've been fiddling with my own code for hours, and I can't seem to figure out why this is happening. Passing normal parameters to these action creators outside of
bindThunkAction
works fine.Another weirdness: even with these errors, the reducer seems to work; but, the types of
params
andresult
, etc have a weird optional-like, for example:number | { undefined & number }
.If one ignores the errors and runs the code with
ts-node
, it executes without errors. Am I losing it?The text was updated successfully, but these errors were encountered: