facebook / facebook/flow

Class-returning-function breaks nominal typing of instances

Abierto
#4,497 1 comentario 2 reacciones 0 asignados Ver en GitHub
bug Effort: hard Typing: other
Lenguaje dominante
Rust
Estrellas
22.3k
Forks
1.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Flow currently returns the same nominal type for functions returning fresh classes, e.g.

```js
function create() {
return class K {};
}

let K1 = create();
(create(): Class); // NG, but Flow yields a false positive
```

I currently have a memoizing polymorphic function that depends on this behavior, i.e.

```js
export class PointerList {
static _specials: { [hash: string]: Class> };
static of | BoolList>(_R: Class): Class> {
const hash = _R._hash();
const cached = this._specials[hash];
if (cached) {
return ((cached: any): Class>);
}

class List extends ByteAlignedList {
static _hash(): string {
return "L("+_R._hash()+")";
}
// ...
}

return this._specials[hash] = List;
}
}
```

Can I rely on this pattern?

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.