facebook / facebook/flow

Intersections have order dependent behavior

Abierto
#1,735 2 comentarios 10 reacciones 0 asignados Ver en GitHub
Typing: spread Typing: unions/intersections
Lenguaje dominante
Rust
Estrellas
22.3k
Forks
1.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

```
// @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.

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.