facebook / facebook/flow

Object literal warning on union objects

Aperta
#4,683 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
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.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.