facebook / facebook/flow

Support for lower type bounds

Abierto
#3,950 0 comentarios 0 reacciones 0 asignados Ver en GitHub
feature request
Lenguaje dominante
Rust
Estrellas
22.3k
Forks
1.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.