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

Property cannot be accessed on any member of intersection type intersection #1759

Closed
7ynk3r opened this issue May 7, 2016 · 10 comments
Closed

Property cannot be accessed on any member of intersection type intersection #1759

7ynk3r opened this issue May 7, 2016 · 10 comments

Comments

@7ynk3r
Copy link

@7ynk3r 7ynk3r commented May 7, 2016

This should work

// @flow
'use strict';

type X = ({a:true} & {b:string}) | ({a:false} & {c:string});
// type X = {a:true, b:string} | {a:false, c:string}; // this works.

function hello(x:X): string{
  return x.a ? x.b : x.c;
}

This is the error

test.js:8
  8:   return x.a ? x.b : x.c;
                    ^^^ property `b`. Property cannot be accessed on any member of intersection type
  8:   return x.a ? x.b : x.c;
                    ^ intersection
  Member 1:
    4: type X = ({a:true} & {b:string}) | ({a:false} & {c:string});
                                           ^^^^^^^^^ object type
  Error:
    8:   return x.a ? x.b : x.c;
                        ^ property `b`. Property not found in
    4: type X = ({a:true} & {b:string}) | ({a:false} & {c:string});
                                           ^^^^^^^^^ object type
  Member 2:
    4: type X = ({a:true} & {b:string}) | ({a:false} & {c:string});
                                                       ^^^^^^^^^^ object type
  Error:
    8:   return x.a ? x.b : x.c;
                        ^ property `b`. Property not found in
    4: type X = ({a:true} & {b:string}) | ({a:false} & {c:string});
                                                       ^^^^^^^^^^ object type

test.js:8
  8:   return x.a ? x.b : x.c;
                          ^^^ property `c`. Property cannot be accessed on any member of intersection type
  8:   return x.a ? x.b : x.c;
                          ^ intersection
  Member 1:
    4: type X = ({a:true} & {b:string}) | ({a:false} & {c:string});
                 ^^^^^^^^ object type
  Error:
    8:   return x.a ? x.b : x.c;
                              ^ property `c`. Property not found in
    4: type X = ({a:true} & {b:string}) | ({a:false} & {c:string});
                 ^^^^^^^^ object type
  Member 2:
    4: type X = ({a:true} & {b:string}) | ({a:false} & {c:string});
                            ^^^^^^^^^^ object type
  Error:
    8:   return x.a ? x.b : x.c;
                              ^ property `c`. Property not found in
    4: type X = ({a:true} & {b:string}) | ({a:false} & {c:string});
                            ^^^^^^^^^^ object type
@nmn
Copy link
Contributor

@nmn nmn commented May 8, 2016

I think & doesn't quite work correctly for extending objects.

@7ynk3r
Copy link
Author

@7ynk3r 7ynk3r commented May 8, 2016

what other alternatives can i use to extend an object?
still this is a bug. i can use & without any problem as long as i don't combine it with |

@nmn
Copy link
Contributor

@nmn nmn commented May 8, 2016

I can't always use & on it's own either. It works most of the times, but every now and then it just breaks down.

It tends to not work when using flow check-contents in a linter plugin

I'm trying to find workaround for now.

@avikchaudhuri
Copy link
Contributor

@avikchaudhuri avikchaudhuri commented Jun 1, 2016

This is going to be fixed in an upcoming release.

@avikchaudhuri avikchaudhuri self-assigned this Jun 1, 2016
@chris-lock
Copy link

@chris-lock chris-lock commented Jun 6, 2016

+1

@ghost ghost closed this in 2df7671 Jun 10, 2016
@kevinSuttle
Copy link
Contributor

@kevinSuttle kevinSuttle commented Jul 27, 2016

@avikchaudhuri I'm still seeing this error, but I'm probably approaching the issue incorrectly. #2135

@natdm
Copy link

@natdm natdm commented May 3, 2017

I am still seeing this issue.

// ... generated.js

// Transaction represents a single atomic transaction in the application
export type Transaction = { 
	description: string, 
	bidder_id: number, // foreign key to bidder table

	stripe_transaction_id: string, 
	event_id: number, // foreign key to event table

	amount: number, // in cents

	fee: number, // in cents

	status: string
}
import type {
    Transaction as transaction,
} from './generated';

// merge types with this ID until Typewriter can get this from the embedded types
type ID = { ID: number };
type UpdatedAt = { UpdatedAt: string };

export type Transaction = ID & UpdatedAt & transaction;

results in: property `ID` Property cannot be accessed on mixed

@heywarddai
Copy link

@heywarddai heywarddai commented May 31, 2017

+2

@natdm
Copy link

@natdm natdm commented Jun 12, 2017

Why is this closed? I still have the same issue I posted above with .47

@ummahusla
Copy link

@ummahusla ummahusla commented Jun 23, 2017

Still get this error. Just created a new issue.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants