facebook / facebook/flow

Flow should force overriding if a method returns this

未關閉
#2,998 2 則留言 0 個 reaction 已指派 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 摘要。