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

Comments

Projects
None yet
9 participants
@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

This comment has been minimized.

Show comment
Hide comment
@nmn

nmn May 8, 2016

Contributor

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

Contributor

nmn commented May 8, 2016

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

@7ynk3r

This comment has been minimized.

Show comment
Hide comment
@7ynk3r

7ynk3r 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 |

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

This comment has been minimized.

Show comment
Hide comment
@nmn

nmn May 8, 2016

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@avikchaudhuri

avikchaudhuri Jun 1, 2016

Contributor

This is going to be fixed in an upcoming release.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@chris-lock

chris-lock commented Jun 6, 2016

+1

@ghost ghost closed this in 2df7671 Jun 10, 2016

@kevinSuttle

This comment has been minimized.

Show comment
Hide comment
@kevinSuttle

kevinSuttle Jul 27, 2016

Contributor

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

Contributor

kevinSuttle commented Jul 27, 2016

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

@natdm

This comment has been minimized.

Show comment
Hide comment
@natdm

natdm 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

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

This comment has been minimized.

Show comment
Hide comment
@heywarddai

heywarddai commented May 31, 2017

+2

@natdm

This comment has been minimized.

Show comment
Hide comment
@natdm

natdm Jun 12, 2017

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

natdm commented Jun 12, 2017

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

@ummahusla

This comment has been minimized.

Show comment
Hide comment
@ummahusla

ummahusla Jun 23, 2017

Still get this error. Just created a new issue.

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