facebook / facebook/flow

Object destructuring breaks disjoint union type.

Aperta
#3,932 4 commenti 5 reazioni 0 assegnatari Vedi su GitHub
destructuring Typing: unions/intersections
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

As an example:

```js
type Props =
| { type: 'foo', item: { id: number, parentId: number | null } }
| { type: 'bar', item: { id: number, parentId: number } }

function test(props: Props) {
// This works
const yay = props.type === 'foo'
? props.item.id
: `/parents/${props.item.parentId}/items/${props.item.id}`

// This does not
const { type, item } = props
const boo = type === 'foo'
? item.id
: `/parents/${item.parentId}/items/${item.id}`
}
```

I'm running v0.46. Curiously, the try flow REPL [doesn't exhibit an error](https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAodAXAngBwKZgAKATnDgM5gC8qYYAPmAN5jb4BcYA5FHHFwBowASwx4AtpxbCAJpwB2AV3EAjPMSE4AhsTzyMASTlglq9QxOKYMMAF87tCyzZ5OXFTsEixk5iOOmahpg2rr6RgrKQXYOdKhQivIAxhjCcPKseOQYABQ4pBScJGTkAJTMjnTAwGAAKgAWwpQIcMQA1uSVYEnp2WBYWljUIQXkAHQu1FRU3Lz8YF10dAD8IyVjohIbMmCci0sABsChehjkwAAkTPnrm+JjJ+EytsB351c3FBs+27YHXV1qnVGpQZHAsvIuBguj15H1nLg8EI7jEZhgQQ9RjDehgwIpiDY0YipjMeHwuAslmAAJCrO7bSlLamcI6PM6XJj0tlGF5vDn02R-VC2IA), I'm only getting it locally.

Any ideas?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.