facebook / facebook/flow

Intersections have order dependent behavior

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

```
// @flow
type Foo = {
foo: string,
};

type Bar = {
bar: string,
} & Foo;

type Baz = Foo & {
baz: string,
};

const bat = (foo: Foo) => foo.foo;

export const invalid = ({ bar, ...baz }: Bar) => bar && bat(baz);
export const valid = ({ baz, ...bar }: Baz) => baz && bat(bar);
```

yields

```
src/components/test.js:15
15: export const invalid = ({ bar, ...baz }: Bar) => bar && bat(baz);
^^^^^^^^ function call
14: const bat = (foo: Foo) => foo.foo;
^^^ property `foo`. Property not found in
15: export const invalid = ({ bar, ...baz }: Bar) => bar && bat(baz);
^^^ object pattern spread property

Found 1 error
```

Apologies if the names are confusing, I was trying to reduce the problem to a minimal case. But the point is, `Bar` and `Baz` are, in practice, the same type, however, the intersection operator handles them very differently. I expect this is the root cause of issues such as #1511, #1118, #824, and #1462.

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.