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

Disjoint Union tags has to be located at top level of an object #1931

Closed
sverrejoh opened this issue Jun 11, 2016 · 2 comments
Closed

Disjoint Union tags has to be located at top level of an object #1931

sverrejoh opened this issue Jun 11, 2016 · 2 comments

Comments

@sverrejoh
Copy link
Contributor

The tags in a Disjoint Union has to be located at the top level of the object, and can not be nested in another object. Meaning that the following code will not work:

/* @flow */

type FooStyle = {
    style: {
        width: number,
    },
    data: {
        type: "foo"
    }
}

type BarStyle = {
    style: {
        height: number,
    },
    data: {
        type: "bar"
    }
}

type ElementStyle = FooStyle | BarStyle;

function process(ele: ElementStyle) {
    if (ele.data.type === "bar") {
        // This gives a flow error as height is not found in the object.
        console.log(ele.style.height);
    }
}

Is there any reason for this? I'm working with a library that limits arbitrary properties to a nested object, so I can't add the tag at top level, and I optimistically thought this would work.

@SamChou19815
Copy link
Contributor

This is expected behavior as a limitation of refinements on disjoint union.

@SamChou19815 SamChou19815 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants