-
Notifications
You must be signed in to change notification settings - Fork 122
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
Adjust TypeScript definition for places where actions may not be dispatched #244
Conversation
Thanks for working on this! I don't think we have to give a default of export function run(
f: Function,
options?: {
args?: any[];
forceSync?: boolean;
testInvariants?: boolean;
}
): RunCmd<never>;
export function run<A extends Action, B extends Action>(
f: Function,
options?: {
args?: any[];
failActionCreator?: ActionCreator<A>;
successActionCreator?: ActionCreator<B>;
forceSync?: boolean;
testInvariants?: boolean;
}
): RunCmd<A>; |
Good call on the overloads, that is a better idea. |
Right "overloads" -- I knew there was a word for it that I was forgetting! Anyway this was just my first attempt at crafting an overload. Perhaps we can improve it by making more which are more specific. I'm not sure how to determine what will work best; it's really just trial and error with these kind of overloads. |
@laszlopandy I took a stab at the overloads. Let me know what you think! I agree that it'll take some iterating to get this right. |
index.d.ts
Outdated
|
||
export interface LoopReducer<S, A extends Action = AnyAction> { | ||
(state: S | undefined, action: A, ...args: any[]): S | Loop<S, A>; | ||
export interface LoopReducer<S, A extends Action = AnyAction, B extends Action = A> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laszlopandy I added this so that you can optionally delineate between the set of actions that a reducer consumes vs the set of actions that will be dispatched via loops. I think that this is needed since the set of actions being dispatched may not match, or even be a subset of, the actions being consumed. The Loop actions default to the consumed actions though, so this remains backwards compatible. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should consider #247 when changing LoopReducer
Did a push with the default action enforcement discussed in #247 |
@bdwain @laszlopandy As I've been working through this, there's a fundamental thing that I'm wondering about.. Do we need to enforce type checking on actions emitted via Redux Loop? i.e., do we need to force the user to enumerate the types of actions that various commands can emit?
Right now the PR has the slight alternation to master above, which indicates that a loop reducer returns a loop that is a set of known actions. So one might have:
And if you made a change..
You would end up with an error since I'm not sure that we need to be enforcing this. It doesn't really matter what actions Loop emits. It could be any action in the system and I don't see why we need to force the user to enumerate the types of actions Loop cares about. I do think we should enumerate the types of actions handled, since not handling an expected action is probably a bug. I also think we need to specify action information where we have action creators arguments (such as But.. It feels overly verbose to force the user to enumerate the types of actions that Loop is emitting into the Redux system. If we dropped this enforcement, we could dramatically simplify the type system. Especially since we have commands that take multiple actions which makes doing the Thoughts? |
I think that makes sense @nweber-gh |
Did a push with the proposed changes. Tests are clean. I also added actual linting for the TypeScript stuff, since the linter was all confused. |
As discussed in issue #243 actions are not always dispatched from loops. This PR defaults the
Action
generic tonever
in the various spots where an action may not be dispatched.