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

[WIP] Polymorphic Flow Types #356

Closed
wants to merge 2 commits into from

Conversation

leoasis
Copy link
Contributor

@leoasis leoasis commented Jul 29, 2015

Adding Flow types again, this time polymorphic so that we can define custom action types in the apps and make them type check correctly when using them with redux. Addresses #290

So far this only has the createStore typed, will work on the other util functions. Just wanted to show the progress so far and if anyone wants to chime in and give feedback, more than welcome!

I have a temporary file in the counter example that is the actual one being type checked, instead of the real entry point (since I haven't yet typed the other util functions), which is sample.js. If you want to play around, uncommenting the lines there and running flow will correctly show the type errors.

You may need to change the counter's package.json dependencies to make redux point to file:../../ so that it grabs the code from the real source instead of npm (which doesn't have flow types yet).

Caveat so far: There is a bug in Flow (facebook/flow#582) which forces us to explicitly specify the init action type inside the union list of the app's action types. Until that gets fixed, I'm afraid we'll need to keep doing that instead of having that type provided by redux itself, which is defined in the flow/types.js file but not used.

switch (action.type) {
case INCREMENT_COUNTER:
case 'INCREMENT_COUNTER':
return state + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will returning non-number fail the type check here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!

@gaearon
Copy link
Contributor

gaearon commented Jul 29, 2015

This is really really good so far! Thanks for working on it. The next (in terms of importance) after createStore is combineReducers and bindActionCreators I think.

@leoasis
Copy link
Contributor Author

leoasis commented Jul 29, 2015

@gaearon yes, been trying to think how to type those in a polymorphic way. Will push updates into this PR

@quicksnap
Copy link
Contributor

💃 👯 Would love types! Thanks for working on this.

@gaearon
Copy link
Contributor

gaearon commented Aug 14, 2015

Closing, so I can delete breaking-changes-1.0.
Please resubmit against master.

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

Successfully merging this pull request may close these issues.

3 participants