flowjs/flow.js

"Could not decide which case to select" error occurs based on casing

conradreuter opened this issue · 1 comments

When using discriminated unions I noticed something odd:

This works: (Try Flow)

type Config =
  | {| +kind: typeof Kind.FOO |}
  | {| +kind: typeof Kind.BAR |}

const Kind = Object.freeze({
  FOO: ('FOO': 'FOO'),
  BAR: ('BAR': 'BAR'),
})

const fooConfig: Config = {kind: Kind.FOO}
const barConfig: Config = {kind: Kind.BAR}

but this gives [speculation-ambiguous]: (Try Flow)

type Config =
  | {| +kind: typeof Kind.foo |}
  | {| +kind: typeof Kind.bar |}

const Kind = Object.freeze({
  foo: ('FOO': 'FOO'),
  bar: ('BAR': 'BAR'),
})

const fooConfig: Config = {kind: Kind.foo}
const barConfig: Config = {kind: Kind.bar}

Note that the only difference is in the keys of the Kind object.

Also note that the keys of Kind don't need to be equal to the values for this to work. (Try Flow)

Please submit your issue to the corresponding project page (https://github.com/facebook/flow ?)
Thank you.