facebook / facebook/flow

Object destructuring breaks disjoint union type.

Đang mở
#3,932 4 bình luận 5 reaction 0 người được giao Xem trên GitHub
destructuring Typing: unions/intersections
Ngôn ngữ chính
Rust
Star
22.3k
Fork
1.9k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.