facebook / facebook/flow

Unexpected error on object intersection

Abierto
#3,148 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
22.3k
Forks
1.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.