-
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
Could not decide which case to select #2892
Comments
Here is a problem: when you something to have type |
But when |
Well, you can actually change (mutate) it, but object spread merges branches together |
Off course, but redux (and functional programming in general) is build around immutability to knows when changes has been made. I understand it's hard for flow to choose which type it has to output, but it is not impossible, it has the information to decide, right? Unfortunately for me it is now impossible to add flow type to this situation. Thanks for your feedback. |
You could refine function transform(input: State, lang: string): State {
if (state.type === 'init')
return {
type: 'init',
...input,
lang
}
return {
type: 'second',
...input,
lang
}
} |
Yes, but I have to much types, it would only make the code less easy to manage which is not really beneficial. I think I am going to extract that code into another reducer. Still this enhancement would be very welcome. |
I was thinking some more: Why does flow needs to know which one it is? Can't the function just return a union type in the case where it's undecidable? It only needs to check if the newly created object can match |
Apologies for bumping such an old thread, but I'm curious if anyone has found a workaround for this. Manual refinement works fine if the disjoint union has 2 or 3 cases, but it not reasonable for larger sets. I'm not clear on why creating a new object from an old one via spread and changing one property (shared amongst all cases) would not pass Flow checks. |
Any solution to this yet? |
ReduxState is a state declared in flow typed directory as global. I don't know what the error means. After I upgraded |
Some built-in "private" type will be very useful. [JUST PROPOSAL, NOT IMPLEMENTED] |
+1 for |
The issue is actually about broken spread. There is a PR that will fix the issue: #7298 |
Guess managed to rewrite via Object.assign |
This code no longer errors on master |
This
Results in the next error.
Al the cases have
lang
, so I think it should return the same type as it gets, like the next situation, which works fine:Casting the output to
State
ortypeof input
does not resolve the issue.The text was updated successfully, but these errors were encountered: