facebook / facebook/flow

Support for lower type bounds

Aperta
#3,950 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
feature request
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Flow supports bounded polymorphism (https://flow.org/blog/2015/03/12/Bounded-Polymorphism/), a way of declaring upper type bounds.

Is there a way to express a lower type bound? I've tried using `$Supertype` which doesn't work ([flow link](https://flow.org/try/#0MYewdgzgLgBAZiEMC8MA8BBANDAQgLhgBIBlAVwAcBTAJygE9rMA+ZgCgENDsYAjQ3AEoBKZjADeAKBgwaVKGRpgYUGmSowA-DA4xCvANySAvgaA))

```jsx
const foo = >(a: A, b: B): B => {
return true ? a : b;
};
```

I need to use this to type a `getOrElse`:

```jsx
const getOrElse = >(opt: Option) => (def: B): B => {
if (opt.isEmpty() {
return def;
} else {
return opt.get();
}
};
```

Am I using `$Supertype` incorrectly, and is there a better way to express this?

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.