facebook / facebook/flow

Flow should force overriding if a method returns this

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

説明

While I was brainstorming a solution for #2959 I stumbled upon this issue.

The gist is that flow should force an override of `method` in `B`. Otherwise we can get false positives.
A reproducible case:

```js
class A {
name: string
constructor(name: string) {
this.name = name
}

method(f: (from: string) => string): this {
return new this.constructor(f(this.name))
}
}

class B extends A {
surname: string
constructor(name, surname) {
super(name)
this.surname = surname
}
}

const b = new B('a', 'b')
const b2 = b.method(() => 'b')
// surname is undefined but there's no error
const surname: string = b2.surname
```

If you find it a welcome addition I will try to implement it.

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

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

評価

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

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

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