facebook / facebook/flow

Object destructuring breaks disjoint union type.

Offen
#3,932 4 Kommentare 5 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
destructuring Typing: unions/intersections
Vorherrschende Sprache
Rust
Sterne
22.3k
Forks
1.9k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.