facebook / facebook/flow

Cannot infer Object type if it is union type on interface property

Đang mở
#2,437 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
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ả

Hi, I'm facing this problem but I cannot find the description about this behavior in documentation.

**Version** 0.32.0

**Reproduction**
https://tryflow.org/?code=LyogQGZsb3cgKi8KCmludGVyZmFjZSBPcHRpb25zIHsKICBib2R5OiBPYmplY3QgfCBGb3JtRGF0YTsKfQoKY29uc3Qgb3B0aW9uczogT3B0aW9ucyA9IHsKICBib2R5OiB7CiAgICBmb286ICdmb28nLAogICAgYmFyOiB0cnVlCiAgfQp9

``` js
/* @flow */
interface Options {
body: Object | FormData;
}

const options: Options = {
body: {
foo: 'foo',
bar: true
}
}
```

**Expected behavior**
Successfully compiled without error.

**Actual behavior**
Failed to compile and the following error is printed.

```
test.js:8
8: body: {
^ property `bar`. Property not found in
4: body: Object | FormData;
^^^^^^^^ FormData

test.js:8
8: body: {
^ property `foo`. Property not found in
4: body: Object | FormData;
^^^^^^^^ FormData

Found 2 errors
```

Note that if I remove `FormData` from the type of `body` or cast `body` value to `Object` explicitly, the error is not occurred.

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.