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

Flow types, take 3 (actually 4) #254

Merged
merged 5 commits into from
Jul 19, 2015
Merged

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Jul 12, 2015

It works!

(Did I git it right this time?)

export type Middleware = (methods: { dispatch: Dispatch, getState: () => State }) => (next: Dispatch) => Dispatch;
export type Store = { dispatch: Dispatch, getState: State, subscribe: Function, getReducer: Reducer, replaceReducer: void };
export type CreateStore = (reducer: Function, initialState: any) => Store;
export type HigherOrderStore = (next: CreateStore) => CreateStore;
Copy link
Contributor

Choose a reason for hiding this comment

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

Woah. That's pretty awesome.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops obviously the type of reducer should be Reducer :)

@acdlite
Copy link
Collaborator Author

acdlite commented Jul 12, 2015

Oh shit just realized I forgot to add /* @flow */ to the top of the types file. :D Surfaced a few errors. I'll fix and update.

@gaearon
Copy link
Contributor

gaearon commented Jul 12, 2015

Can we integrate this into the build pipeline? Check Flow before running tests?

@acdlite
Copy link
Collaborator Author

acdlite commented Jul 12, 2015

@gaearon gaearon mentioned this pull request Jul 12, 2015
@gaearon
Copy link
Contributor

gaearon commented Jul 12, 2015

Can you please bring this up to date with the last changes I made to breaking changes branch?

@gaearon
Copy link
Contributor

gaearon commented Jul 12, 2015

Also, should we take this in now? After 1.0?

@gaearon gaearon mentioned this pull request Jul 14, 2015
@gaearon
Copy link
Contributor

gaearon commented Jul 14, 2015

Also, do we want https://github.com/babel-plugins/babel-plugin-flow-comments for the non-minified builds?

@chicoxyzzy
Copy link
Contributor

Don't sure flow-comments plugin is necessary. It's not very readable and flow is useful for compile time not after.

@chicoxyzzy
Copy link
Contributor

http://flowtype.org/blog/2015/02/20/Flow-Comments.html
Flow comments are alternative to standard Flow annotations actually

@gaearon
Copy link
Contributor

gaearon commented Jul 14, 2015

It's not very readable and flow is useful for compile time not after.

Still might be useful for people browsing the compiled source (e.g. when debugging some issue).
Writing them as comments gets cumbersome, but I'd welcome comments in the compiled NPM output.

@chicoxyzzy
Copy link
Contributor

Are you talking about devs of Redux (who should actually use uncompiled sources) or devs who use Redux? IMO not so much JS devs are familiar with Flow so it's more code pollution than code documentation.

@gaearon
Copy link
Contributor

gaearon commented Jul 15, 2015

I'm talking about users. I think our core audience is at least passingly familiar with Flow. Also, I'd say even a person unfamiliar with Flow wouldn't have a problem reading most Flow annotations.

Anyway I don't have a strong opinion here. Let's see what others have to say.

@taylorhakes
Copy link
Contributor

I really like the type annotation comments in the code. It would help me find a type bug earlier.

The only downsides are file size and confusion. I don't imagine too many people confused by the comments (they are just comments) and I think it adds a lot of value.

@gaearon
Copy link
Contributor

gaearon commented Jul 15, 2015

File size isn't a problem because comments are stripped by any minification tool.

@chicoxyzzy
Copy link
Contributor

I think our core audience is at least passingly familiar with Flow.

It would be much better to have types in jsDoc for non-minified build rather then not working actual alternative Flow type annotation. BTW personally I don't care much about it.

It would help me find a type bug earlier.

I don't think so. You will find a bug for same time as without these comments cause they have nothing to do with types and they can't say "Hey! I want String not Integer!". All they can say is "Hey! Hey look at me! I'm String! Really!" when you scrolling your code. And all of them will do it. Do you really think it can help?

@chicoxyzzy
Copy link
Contributor

Also Flow comments are created as a temporary solution which should help in evaluating migration to standard Flow type annotation not for code documentation. jsDoc can help by static analysis, autocompletion and function parameters hinting. Flow comments can't do any of that

@gaearon gaearon mentioned this pull request Jul 15, 2015
@chicoxyzzy
Copy link
Contributor

But maybe I'm wrong... For example can I use standard Flow annotations in my app together with Redux's non-minified version Flow comments? Does someone has any experience with such workflow?

@chicoxyzzy
Copy link
Contributor

But maybe I'm wrong... For example can I use standard Flow annotations in my app together with Redux's non-minified version Flow comments? Does someone has any experience with such workflow?

This is the answer http://flowtype.org/docs/third-party.html

@chicoxyzzy
Copy link
Contributor

So I suggest supporting Flow's interface file, TypeScript's tsd file and cut of all Flow annotations from any builds

@taylorhakes
Copy link
Contributor

File size isn't a problem because comments are stripped by any minification tool.

@gaearon Yes. Minified is the same if comments exist or not. I thought we talking about unminified? That's where the difference lies.

@chicoxyzzy Unfortunately, currently, the flow type annotations are stripped before publishing to NPM. You can't access the raw flow files via NPM. A flow interface file like you linked or correct comments would work to remedy a full flow app.

If you aren't using flow, the type information inline (via flow comments, correct if possible, or jsDoc) is useful when debugging library code. I can inspect the 'hello' value and see /*: number*/ next to it.

I am definitely for a correct flow workflow. I am just saying, unless someone is working on creating jsDoc processors or correct flow comments, I think there is value in the flow comments with very little downside.

@hzoo
Copy link

hzoo commented Jul 16, 2015

If you see any issues with the babel plugin's comment output - def make an issue (if it's not the one already there) in the repo or ping me

@gaearon
Copy link
Contributor

gaearon commented Jul 19, 2015

I updated the pull request to match the 1.0 API.
This is ready to merge, but I wonder if there is anything we can (or should) expose to Flow users..

(e.g. #206?)

@gaearon
Copy link
Contributor

gaearon commented Jul 19, 2015

In particular I'm interested what we need to change to enjoy this kind of static analysis: facebookarchive/flux#243

Do we need to change more signatures to be generic to allow this? Should it be createStore<MyState, MyAction>()? How does this play with the middleware? And how do we expose these definitions?

gaearon added a commit that referenced this pull request Jul 19, 2015
Flow types, take 3 (actually 4)
@gaearon gaearon merged commit 98ab1de into breaking-changes-1.0 Jul 19, 2015
@gaearon gaearon deleted the flow-types-take-3 branch July 19, 2015 19:41
@gaearon
Copy link
Contributor

gaearon commented Jul 19, 2015

I've merged this in the current state, but I opened #290 to track improvements to our definitions to allow facebookarchive/flux#243-like static analysis.

@gaearon
Copy link
Contributor

gaearon commented Jul 19, 2015

Also Flow comments are created as a temporary solution which should help in evaluating migration to standard Flow type annotation not for code documentation.

This says otherwise:

We plan to update our Flow transformation to wrap Flow syntax with these special comments, rather than stripping it away completely. This will help people write Flow code but publish code that works with or without Flow.

It's not just a temporary measure as I read it; it's a solution they plan to use for publishing Flow code on NPM. You don't need separate interface definitions if the comments “just work”.

I'm going to investigate the Babel plugin. If it helps Flow users consume (and interpret!) Redux code with annotations, isn't that awesome?

@volkanunsal
Copy link

For what it's worth, in the past, I've found flow-comments useful as a supplement to Flow types. There will be cases when Flow types are in conflict with the ES6 or ES7 notation, e.g. argument destructuring.

@gaearon
Copy link
Contributor

gaearon commented Jul 19, 2015

One thing I'm not sure of is how to handle the fact that our types are in a separate types file.
@hzoo Can the plugin handle import type... somehow?

@hzoo
Copy link

hzoo commented Jul 20, 2015

@gaearon I see you already got a PR for import type 😄

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

Successfully merging this pull request may close these issues.

6 participants