facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.09k stars 1.86k forks source link

Function call is messing up with intersection types #4802

Open eliseumds opened 7 years ago

eliseumds commented 7 years ago

Check out line 38 of the following example: https://goo.gl/AdmME5. Does anyone know why it's failing with property 'size'. Property cannot be accessed on any member of intersection type... instead of pointing out first that the second argument passed to mapPropToClass is incorrect?

dperetti commented 7 years ago

Related: https://github.com/facebook/flow/issues/4586

asolove commented 7 years ago

I think the linked issue explains this reasonably well. This is expected though confusing behavior. I’m going to close this issue since it’s not a bug, but am happy to help with adjusting that code to work.

dperetti commented 7 years ago

Returning a misleading, unhelpful error message to the user does sound a bit like a bug, though !

eliseumds commented 7 years ago

I definitely agree with @dperetti.

asolove-stripe commented 7 years ago

This is now improved in Flow 0.55! I had to remove the JSX from the example because Try Flow currently isn't working with JSX. After doing that, the new error message is:

33:     const { size, tracking, ...otherProps } = this.props;
                ^ property `size`. Property cannot be accessed on any member of intersection type
33:     const { size, tracking, ...otherProps } = this.props;
                                                  ^ intersection
Member 1:
26: type ColProps = BoxProps & {
                    ^ BoxPropsError:
33:     const { size, tracking, ...otherProps } = this.props;
                ^ property `size`. Property not found in
26: type ColProps = BoxProps & {
                    ^ object type
Member 2:
26: type ColProps = BoxProps & {                               ^ object typeError:
38:     mapPropToClass('size', size);
                            ^ number. This type is incompatible with the expected param type of
8: function mapPropToClass(key: string, prop: Object) {
                                              ^ object type

Which helps us reconstruct Flow's reasoning:

I think this makes stuff a lot clearer and so this issue is fixed. WDYT, @eliseumds?

eliseumds commented 7 years ago

@asolove-stripe sweet! That's way more useful, thanks =)

samwgoldman commented 7 years ago
38:     mapPropToClass('size', size);
                            ^ number. This type is incompatible with the expected param type of

This part of the error seems bogus, right? Like the error position is way off.