facebook / facebook/flow

Flow should force overriding if a method returns this

Đang mở
#2,998 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Rust
Star
22.3k
Fork
1.9k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.