-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Intersection breaks disjoint unions #1462
Comments
Interesting thing: order matters. If you declare types like this: type A = {
type: 'A',
foo: number
} & Common;
type B = {
type: 'B',
foo: Array<number>
} & Common; This example begins to fail correctly, but refinement doesn't work anymore: type Common = {
};
type A = {
type: 'A',
foo: number
} & Common;
type B = {
type: 'B',
foo: Array<number>
} & Common;
type MyType = A | B;
function print(x: number) {
console.log(x);
}
function printAll(val: MyType) {
if (val.type === 'A') {
print(val.foo);
} else {
val.foo.forEach(print);
}
} Outputs:
|
Any progress on this? How to create unions with common part? |
duplicate: #1118 |
This will be fixed in an upcoming release. |
@avikchaudhuri flow 0.27, not fixed for me: // @flow
type DataBase = {
id: string;
name: string;
};
type UserData = DataBase & {
kind: 'user';
};
type SystemData = DataBase & {
kind: 'system';
n: number;
}
type Data = UserData | SystemData;
function test(data: Data): void {
if (data.kind === 'system') {
if ((data: SystemData).n === 1) { // Error: this type is incompatible with
return
}
}
} |
Any updates on this, I'm using the latest version and this is still a problem. |
This type-checks, although it shouldn't:
If I remove intersection it works as expected.
The text was updated successfully, but these errors were encountered: