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

FlowTyped Declarations #73

Open
colshacol opened this issue Jan 9, 2018 · 5 comments
Open

FlowTyped Declarations #73

colshacol opened this issue Jan 9, 2018 · 5 comments

Comments

@colshacol
Copy link

colshacol commented Jan 9, 2018

In usage with Flow, I get errors like this:

screen shot 2018-01-09 at 12 14 30 am

I am wondering that, since the values passed into condition are negated to truthy or falsey, shouldn't it accept any type?

Apologies if this question belongs elsewhere. If so, please do direct me.

@colshacol
Copy link
Author

Current declarations:

screen shot 2018-01-09 at 12 17 29 am

What I believe it should be:

screen shot 2018-01-09 at 12 17 42 am

@AlexGilleran
Copy link
Owner

Ehhhh I see your point but I actually like that it forces you to put the !! in front and say "I definitely want to check for truthiness here, it's not that I've just got the wrong variable/property".

You can just use your own definitions in place of the ones supplied right?

@colshacol
Copy link
Author

@AlexGilleran Apologies, I am constantly at 200% capacity and forgot to take care of this issue. -- Yeah, I was able to patch it up without any issues.

I think it may boil down to opinion on this, but thinking about what I've used, personally, as well as what I have seen in the community, it is the norm to follow conventions such as

if (foo) { ... }

or

foo && whatever;

etc...

In places that values are negated by default, I don't see many explicitly negating.

@JalilArfaoui
Copy link

Hello @AlexGilleran

I agree it is a matter of opinion if we should or not have an explicit boolean cast in conditions.

Except that I think, like @colshacol, that we should have a consistent behavior between if (foo) and <If condition={foo}>.

So, since Flow does not raise an error on if statement with non-boolean value, I think this link should not either.

https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swo44AKADwC4wBnfAJ0OwHMBKep1jsAN6owYQlDA1Og4SLDMApvkzNS1ANwyAvjIVKVYAEQATeVACGmGPkYs27Axu1A

@draperunner
Copy link

I agree @colshacol and @JalilArfaoui . Since it is so obvious that whatever passed into <If condition={}> will be treated as a boolean, like a normal if statement in JavaScript, I think it should be typed as any.

In my project we end up casting all statements with Boolean() like this: <If condition={Boolean(...)}>, which I think is just noisy.

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

4 participants