Union type restrictions don't work when used within other objects
- 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.