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

Fix MiddlewareAPI in .ts #2362

Closed
gorshkov-leonid opened this issue Apr 20, 2017 · 6 comments
Closed

Fix MiddlewareAPI in .ts #2362

gorshkov-leonid opened this issue Apr 20, 2017 · 6 comments

Comments

@gorshkov-leonid
Copy link

gorshkov-leonid commented Apr 20, 2017

MiddlewareAPI should have 2 params in type same as flow-typed/redux.js:

https://github.com/reactjs/redux/blob/master/index.d.ts#L256-L259

@aikoven
Copy link
Collaborator

aikoven commented Apr 21, 2017

Should it? Dispatch is able to accept any action, not just a specific subtype of {type: string}.

@gorshkov-leonid
Copy link
Author

generic type of state vs generic type of action. it is differen things...

@gorshkov-leonid
Copy link
Author

click on links please...

@aikoven
Copy link
Collaborator

aikoven commented Apr 21, 2017

I did.

State type is generic because it depends on your state shape.

Actions are not restricted to any subtype of {type: string}: dispatch accepts any object with type property, even if actions in your codebase are all of the specific shape e.g. {type: string, payload: object}. Imagine a third-party library that has its own action shapes.

Also, there might be a misconception with the generic parameter of Dispatch: the S in Dispatch<S> is not the action type, but the state type. You may notice that Dispatch signature doesn't even use this parameter:

interface Dispatch<S> {
    <A extends Action>(action: A): A;
}

The reason for this is to allow middlewares to augment this interface with custom signatures, i.e. redux-thunk. See #1537

@timdorr
Copy link
Member

timdorr commented Apr 21, 2017

@aikoven is correct here. Because you can enhance the store with middleware to accept any type of input as an "action", it needs to be generic.

@timdorr timdorr closed this as completed Apr 21, 2017
@gorshkov-leonid
Copy link
Author

OK. I understood. Yes it is logical. But it is not clear at first sight. Flow js - 2 type parameters. Ts - 1 type parameter. Think you need to leave a comment in code for the descendants

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

3 participants