facebook / facebook/flow

[bug] Intersection with a tagged union unable to refine type

Abierto
#3,391 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

```js
/* @flow */

type A = {a: string}
type B = {b: string, type: 'b'}
type C = {c: string, type: 'c'}
type BorC = B | C
type ABC = A & BorC

const m: ABC = {type: 'b', a: '', b: ''}

if (m.type === 'b') {
m.b // Error!
// Also interesting. If you have this line, then the `const m` line gets
// a flow error. Remove the line, and the error on `const m` goes away.
}
```

[run it on tryflow](https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoVAXAngBwKZgCCYAvGAN4CGAXGAM4YBOAlgHYDmAvprgQEKkKAI1oMWHADRhs+WgHIhc7jIIBhQeQDGopm3ZSV8zUp74wfOI3VkBAHzCrTBQn2tEwAMnOXHKogLJiLz4nIjcgh1CXS0JwuzD0TThWBjAAW1oXN3JDMAU5KRE8ygKwGjyTYFBUZigwAAo0gDo-Eja8xQBKClQwdKahVG4q5DRUJJSMMFZMi0ZYjVz8qXK5UqK17lqG1hbeUnb87vJe6YGhoA)

However, a union of intersections works fine
```js
type A = {a: string}
type B = {b: string, type: 'b'}
type C = {c: string, type: 'c'}

type AB = A & B
type AC = A & C
type ABorAC = AB | AC

const n: ABorAC = {type: 'b', a: '', b: ''}
if (n.type === 'b') {
n.b // no error
}
```

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.