facebook / facebook/flow

Unexpected error on object intersection

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

Hey! This may be a misunderstanding of how intersection types work [in Flow] but to me I'd expect this to work. Hopefully there's a logical alternative or it may just be a bug! :)

Flow version is latest (v0.37.2 I believe).

Application code:

```
import {Record} from 'immutable';
const ARecord = Record({a: undefined});

type A = ImmRecord<{a: string}>;
type B = ImmRecord<{a: '2'}>;

const b: B = new ARecord({a: '2'});
const a: A = b;
```

`ImmRecord` type declaration:

```
import type {Map, Seq} from 'immutable';

declare type ImmRecord = {
withMutations: (u: Function) => ImmRecord,
merge: (v: $Shape) => any,
get: (k: string, d?: any) => any,
set: (k: string, v: any) => ImmRecord,
setIn: (k: Array, v: any) => ImmRecord,
update: (k: string, u: (any) => any) => ImmRecord,
updateIn: (k: Array, u: (any) => any) => ImmRecord,
entrySeq: () => Seq,
} & T;

```

And the errors I see:

```
55: const a: A = b;
^ intersection. This type is incompatible with
9: declare type ImmRecord = {
^ object type. See lib: flow/immutable.js.flow:9
Member 1:
9: declare type ImmRecord = {
^ object type. See lib: flow/immutable.js.flow:9
Error:
51: type A = ImmRecord<{a: string}>;
^^^^^^ string. Expected string literal `2`
52: type B = ImmRecord<{a: '2'}>;
^^^ string literal `2`
Member 2:
52: type B = ImmRecord<{a: '2'}>;
^^^^^^^^ object type
Error:
9: declare type ImmRecord = {
^ property `merge`. Property not found in. See lib: flow/immutable.js.flow:9
52: type B = ImmRecord<{a: '2'}>;
^^^^^^^^ object type

// next error...

55: const a: A = b;
^ intersection. This type is incompatible with
51: type A = ImmRecord<{a: string}>;
^^^^^^^^^^^ object type
Member 1:
9: declare type ImmRecord = {
^ object type. See lib: flow/immutable.js.flow:9
Error:
51: type A = ImmRecord<{a: string}>;
^^^^^^^^^^^ property `a`. Property not found in
9: declare type ImmRecord = {
^ object type. See lib: flow/immutable.js.flow:9
Member 2:
52: type B = ImmRecord<{a: '2'}>;
^^^^^^^^ object type
Error:
51: type A = ImmRecord<{a: string}>;
^^^^^^ string. Expected string literal `2`
52: type B = ImmRecord<{a: '2'}>;
^^^ string literal `2`
```

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.