facebook/idx

Add support for union types

Closed this issue · 1 comments

When I provide the following function definition:

type TestT = { x?: { z: boolean } }

function somefn(t: TestT) {
  return idx(t, _ => _.x.z)
}

flow compiles with no errors. however, when I change the definition of TestT to the following:

type TestT = { y: string } | { x?: { z: boolean } }

Flow returns the following error (at the usage of idx above): "property x Property not found in object type"

My bad - this is a misunderstanding of flow. If you change the idx call to: return t.x && t.x.z you get the same error. The solution is to use exact types to define the disjoint union.