flowjs / flow.js

A JavaScript library providing multiple simultaneous, stable, fault-tolerant and resumable/restartable file uploads via the HTML5 File API.
Other
2.96k stars 346 forks source link

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

Closed conradreuter closed 3 years ago

conradreuter commented 3 years ago

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)

drzraf commented 3 years ago

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