-
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
Spread on union type fails with "Could not decide which case to select" #6342
Comments
Any progress on this? Is there a workaround annotation we could use in the meantime? |
Spreads on objects are have a few issues at the moment and are being reworked (hopefully soon) |
This doesn't really have to do with spread, you get the same error when you do the follow (which is essentially doing the same thing as spread): function foo( body:Action):Action {
return { name: body.name };
} |
Oh true, this is a separate bug. |
Is there anything we can do to work around this atm? I'm also running into this issue and it is quite frustrating. |
this will fix the issue: #7298 |
This hurts me a bit... but seems to be a workaround: type Action1 = {
name: 'A1',
};
type Action2 = {
name: 'A2',
};
type Action = Action1 | Action2;
function foo(body: Action): Action {
const flowIsBroken: any = { ...body };
const newlyTypedBody: Action = flowIsBroken;
return newlyTypedBody;
}
const shouldBeActionType = foo({ name: 'A1' });
// no errors means it's been typed correctly?
foo(shouldBeActionType); |
This no longer errors in master |
This code:
Try it with Try Flow here
Produces this error:
Replacing
return {...body};
withreturn body
fixes it. It doesn't seem like flow should have to decide on a member of the union just to use the spread operator?The text was updated successfully, but these errors were encountered: