facebook / facebook/flow

Class-returning-function breaks nominal typing of instances

オープン
#4,497 コメント 1 件 リアクション 2 件 担当者 0 名 GitHub で見る
bug Effort: hard Typing: other
主要言語
Rust
スター
22.3k
フォーク
1.9k
PR マージ指標
30日以内にマージされた PR はありません

説明

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?

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。