facebook / facebook/flow

Class-returning-function breaks nominal typing of instances

Offen
#4,497 1 Kommentar 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug Effort: hard Typing: other
Vorherrschende Sprache
Rust
Sterne
22.3k
Forks
1.9k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.