Hacker News new | past | comments | ask | show | jobs | submit login

Um, re-read the documentation:

> These disjoint unions are made up of any number of object types which are each tagged by a single property.

It is clearly a disjoint union in the set-theoretical, not category-theoretical sense.

Let's see their own example:

    // @flow
    type Success = { success: true, value: boolean };
    type Failed  = { success: false, error: string };
    
    type Response = Success | Failed;
    
    function handleResponse(response: Response) {
      if (response.success) {
        var value: boolean = response.value; // Works!
      } else {
        var error: string = response.error; // Works!
      }
    }
Clearly, this union is disjoint because the types `Success` and `Failed` were a priori known to be disjoint.



It doesn't require that. Flow seems to accept all sorts of variations on the following (including X | X):

   type X = { foo: string }
   type Y = { foo: string, bar: string }

   type Foo = X | Y
(Y is a subset of X in that case.)


But then it isn't disjoint.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: