Object literal warning on union objects
- Lingua principale
- Rust
- Stelle
- 22.3k
- Fork
- 1.9k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Here is a minimal test case for an issue I came across.
```javascript
// @flow
export type Apple = { type: 'apple' };
export type Oranges = { type: 'oranges' };
export type Fruit = Apple | Oranges;
function createFruit(type: 'apple' | 'oranges'): Fruit {
return { type };
}
```
Produces the following error:
```
8: return { type };
^ object literal. This type is incompatible with
7: function createFruit(type: 'apple' | 'oranges'): Fruit {
^ union: Apple | Oranges
```
Live example: [flow.org/try](https://flow.org/try/#0PTAEAEDMBsHsHcBQBTAHgB1gJwC6hwJ7rKgCC660JAvKAN75HIBcoA5AIYVVugC+AbhQZseQsVAB5LBwB2Ac2QBnULQbiW7bHMVLegxMMy5GEgGJYArgEs8tcpRIAfKTIXKhiSJdkBjHNawsqC+WMgcOMgWNjgAFBqsnNzIvC5s2u56AJSs0bb0iKCgYTiWWMHqTPxCfIhAA)
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.