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

Unambiguous disjoint union treated as ambiguous #7458

Closed
skeggse opened this issue Feb 8, 2019 · 1 comment
Closed

Unambiguous disjoint union treated as ambiguous #7458

skeggse opened this issue Feb 8, 2019 · 1 comment
Labels
incompleteness Something is missing

Comments

@skeggse
Copy link
Contributor

skeggse commented Feb 8, 2019

Flow version: v0.92.1

Expected behavior

This code should produce no errors:

type StrangeOptional = {allow: string[]} | {allow: null};

// This should be easy for Flow to understand - it's clearly case [1] and not case [2].
({allow: ['com']}: StrangeOptional);

Actual behavior

5: ({allow: ['com']}: StrangeOptional);
    ^ Could not decide which case to select. Since case 1 [1] may work but if it doesn't case 2 [2] looks promising too. To fix add a type annotation to array literal [3].
References:
3: type EitherOptional = {allow: string[]} | {allow: null};
                         ^ [1]
3: type EitherOptional = {allow: string[]} | {allow: null};
                                             ^ [2]
5: ({allow: ['com']}: EitherOptional);
            ^ [3]

Workaround

// Explicitly telling Flow that this is a string array seems to fix the error.
({allow: (['com']: string[])}: StrangeOptional);
  • Link to Try-Flow or Github repo.
@skeggse skeggse added the bug label Feb 8, 2019
@jbrown215 jbrown215 added incompleteness Something is missing and removed bug labels Feb 8, 2019
@SamChou19815
Copy link
Contributor

This now works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incompleteness Something is missing
Projects
None yet
Development

No branches or pull requests

3 participants