facebook / facebook/flow

Union type restrictions don't work when used within other objects

Aperta
#3,749 4 commenti 1 reazione 0 assegnatari Vedi su GitHub
Typing: unions/intersections
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Easiest to explain with code:

```jsx
type MyType = "A" | "B"
type WrappedType = {
myType : MyType
}

const x : MyType = "A";
const y : WrappedType = {
myType : x
}

if (x === 'C') { //Error: string literal `C`. This type is incompatible with string enum
//...
}

if (y.myType === 'C') { //No error, even though this is just as invalid as the above
// And from here `y` is treated as an `Object` type, meaning that any property access is valid:
const z = y.x * 3; // No error, even though this is obviously invalid
}
```

It seems to me that the behavior of the second conditional is a bug. Or is there any reason why flow doesn't detect the errors here?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.